Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSgen_sync_tran_procs

  No additional text.


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

 
Last revision 2008RTM
See also

  sp_articlesynctranprocs (Procedure)
sp_MSdrop_repltran (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