create 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