Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to handle Identity column in replication Expand / Collapse
Author
Message
Posted Saturday, January 22, 2011 11:20 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 3, 2011 1:31 AM
Points: 1, Visits: 11
I am facing a problem while replicating my database. My replication is working fine but I could not use the replicated database becasue all the identity columns in the source table are not identity columns in the target database. Can anybody help me on this
Post #1052026
Posted Sunday, January 23, 2011 2:02 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 3:47 AM
Points: 731, Visits: 2,042
replication needs an identity column create new identity column in both servers.
Post #1052044
Posted Sunday, January 23, 2011 7:59 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 8:32 PM
Points: 3,062, Visits: 2,672
First a correction to the previous post. Replication does not require a table to have an identity column. For transactional replication, all that is required is a declared primary key. It is up to you to deal with how new primary key values are created. One option is to identity but you can choose any method you like. In fact, the primary key does not even need to be numeric.

If you are using an identity column for the primary key, you should also declare it as "NOT FOR REPLICATION". This tells replication that when it inserts a record into the subscriber, do not generate a brand new identity value (similar to using SET INDENTITY_INSERT ON/OFF).

It sounds like there is update activity on the subscriber (I am assuming that you are using transactional replication with updateable subscribers). You will need to manage identity ranges if this is happening (well, actually only if you are inserting on the subscriber). The replication sproc sp_Addarticle allows for this with parameters @auto_identity_range , @pub_identity_range , @identity_range and @threshold. If you are using the new publication wizard, these are available from the article properties in the section "Identity Range Management".

If you are using Merge Replication, I probably would not bother with identity columns at all since Merge Replication requires you to have a row guid column. If you were to have an identity column as well, you would effectively have two completely separate unique columns on the table which is a bit of a waste.



Post #1052121
Posted Monday, April 11, 2011 9:27 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 6, 2013 11:40 AM
Points: 16, Visits: 51
Very informative!
Follow up question, If column ID defined Identity not for replication.
How does SQL Server tells the difference between a user calling a store proc to insert or a batch insert executed by replication, restore by log shipping, bcp, or your own batch insert script?
Also, upon any insert, is the already generated column ID stored in all the log shipping/backup log files?
Many Thanks,
Jeffrey
Post #1091530
Posted Tuesday, April 12, 2011 7:43 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 8:32 PM
Points: 3,062, Visits: 2,672
To tell you the truth, I have never really bothered to discover how SQL Server works out that it is the distribution agent that is inserting data. I assume that the agent is calling system stored procs to do its stuff. If you really need to know, SQL Profiler will most likely give the info.

As with any other INSERT/UPDATE/DELETE, all replication changes to the database are recorded in the transaction log.



Post #1092094
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse