Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSsetup_identity_range

  No additional text.


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

 
Last revision 2008RTM
See also

  sp_MSdrop_rlrecon (Procedure)
sp_MSget_identity_range_info (Procedure)
sp_MSset_new_identity_range (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