Home arrow SQL Server arrow Page 4 - Replication: SQL Server 2000 - Part 2
SQL SERVER

Replication: SQL Server 2000 - Part 2


In this second, and final, installment, Mahesh gives us a step-by-step approach on how to implement replication across a network using SQL Server 2000.

Author Info:
By: Mahesh Kodli
Rating: 5 stars5 stars5 stars5 stars5 stars / 104
November 13, 2003
TABLE OF CONTENTS:
  1. · Replication: SQL Server 2000 - Part 2
  2. · Getting Started: Step-By-Step
  3. · Getting Started: Step-By-Step, Cont'd.
  4. · Code: Stored Procedure
  5. · Getting Started: Step-By-Step, Cont'd.
  6. · General Replication Performance Tips
  7. · Conclusion

print this article
SEARCH DEVARTICLES

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


blog comments powered by Disqus
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

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials