SQL Server
  Home arrow SQL Server arrow Page 4 - Replication: SQL Server 2000 - Part 2
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SQL SERVER

Replication: SQL Server 2000 - Part 2
By: Mahesh Kodli
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 96
    2003-11-13

    Table of Contents:
  • Replication: SQL Server 2000 - Part 2
  • Getting Started: Step-By-Step
  • Getting Started: Step-By-Step, Cont'd.
  • Code: Stored Procedure
  • Getting Started: Step-By-Step, Cont'd.
  • General Replication Performance Tips
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Replication: SQL Server 2000 - Part 2 - Code: Stored Procedure


    (Page 4 of 7 )

    Following is the source code of the stored procedure, which automates the identity range setting process.  The Stored procedure takes ‘PublisherName’ and ‘IdentityRange’ as the parameter and internally uses the ‘SP_addmergearticle’ system stored procedure to set the identity range of all the Published Table articles:

    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_NULLS ON
    GO
    /*
    '***************************************************
    ' Purpose :Add Identity range to the user defined Tables under a given publisher
    ' Inputs  :Publisher Name and Identity Range
    ' Returns         :None
    ' Author       :Mahesh M Kodli
    '****************************************************

    CREATE PROCEDURE AddMergeArticle

    @pPublisherName VARCHAR(255),
    @pIdentityRange BIGINT

    As
     DECLARE @tRV INT
     DECLARE @tArticle VARCHAR(255)
     SET @tRV = 0
     
     DECLARE Merge_Article_Cursor CURSOR FOR

     --Get all the user defined Tables for which to add Identity Range
     SELECT TABLE_NAME TableName FROM INFORMATION_SCHEMA.TABLES  WHERE rtrim(ltrim(table_type))='BASE TABLE'     
    AND TABLE_NAME Not like 'Conflict%' AND TABLE_NAME Not like 'dtproperties'
    AND TABLE_NAME Not like 'sys%' AND TABLE_NAME Not like 'MS%'

     OPEN Merge_Article_Cursor

    FETCH NEXT FROM Merge_Article_Cursor INTO @tArticle
     
     WHILE @@FETCH_STATUS = 0 
     
     BEGIN  

    --Check if the Table has identity column and accordingly set the Auto
    --Identity Range to TRUE or FALSE Before adding Identity Range to the 
    --article
      IF OBJECTPROPERTY ( OBJECT_ID(@tArticle), 'TableHasIdentity') = 1
       
      BEGIN
       
       IF NOT EXISTS (SELECT * FROM sysmergeextendedarticlesview WHERE name = @tArticle AND pubid IN (select pubid FROM sysmergepublications WHERE name like @pPublisherName  AND UPPER(publisher)=UPPER(@@servername) and publisher_db=db_name()))

    BEGIN
        
    --Use the System stored procedure add merge article to add Identity range for -- each article
    EXECUTE sp_addmergearticle @publication = @pPublisherName, @article = @tArticle, @source_owner = N'dbo', @source_object = @tArticle, @type = N'table', @description = null, @column_tracking = N'true', @pre_creation_cmd = N'drop', @creation_script = null, @schema_option = 0x000000000000CFF1, @article_resolver = null, @subset_filterclause = null, @vertical_partition = N'false', @destination_owner = N'dbo', @auto_identity_range = N'true', @pub_identity_range = @pIdentityRange, @identity_range = @pIdentityRange, @threshold = 80, @verify_resolver_signature = 0, @allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true', @check_permissions = 0,@force_invalidate_snapshot=1

    END
        
    END

    ELSE
     BEGIN

      IF NOT EXISTS (SELECT * FROM sysmergeextendedarticlesview WHERE name = @tArticle AND pubid IN (select pubid FROM sysmergepublications WHERE name like @pPublisherName  AND UPPER(publisher)=UPPER(@@servername) and publisher_db=db_name()))

      BEGIN
         
       EXECUTE sp_addmergearticle @publication = @pPublisherName, @article = @tArticle, @source_owner = N'dbo', @source_object = @tArticle, @type = N'table', @description = null, @column_tracking = N'true', @pre_creation_cmd = N'drop', @creation_script = null, @schema_option = 0x000000000000CFF1, @article_resolver = null, @subset_filterclause = null, @vertical_partition = N'false', @destination_owner = N'dbo', @auto_identity_range = N'False', @pub_identity_range = NULL, @identity_range = NULL, @threshold = NULL, @verify_resolver_signature = 0, @allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true', @check_permissions = 0,@force_invalidate_snapshot=1

      END
     
      END
     
       FETCH NEXT FROM Merge_Article_Cursor INTO @tArticle 
     
      END 
     
     CLOSE Merge_Article_Cursor 
     DEALLOCATE Merge_Article_Cursor
     IF (@@ERROR <> 0)
     BEGIN
      SELECT @tRV = -95  --UnSuccessful
      GOTO XIT
     END
     XIT:
     RETURN @tRV

    More SQL Server Articles
    More By Mahesh Kodli


       · very well explained.
     

    SQL SERVER ARTICLES

    - Executing SQL Server Stored Procedure from P...
    - How to Search for Date and Time Values Using...
    - Replication: SQL Server 2000 - Part 2
    - Replication: SQL Server 2000 - Part 1
    - SQL Sever: Storing Code in Binary or Text Fi...
    - Execute SQL on Multiple Tables/Columns - New...
    - How to Connect to a SQL Server from Visual F...
    - SQL Server Hardware Tuning and Performance M...
    - Primary Key on Multiple Tables – New RDBMS C...
    - Migrating from Sybase to SQL Server
    - What's Best for DBAs? GUI or T-SQL Comma...
    - How to Perform a SQL Server Performance Audit
    - An Introduction To The Bulk Copy Utility
    - SQL Server Stored Procedures 101
    - Building Your First SQL Server 2000 Database







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek