Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MScreatelightweightdeleteproc

  No additional text.


Syntax
create 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

 
Last revision 2008RTM
See also

  sp_MScreatelightweightarticleprocs (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash