Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to handle Identity column in replication


How to handle Identity column in replication

Author
Message
mbsajeev
mbsajeev
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
Latheesh NK
Latheesh NK
Right there with Babe
Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)

Group: General Forum Members
Points: 739 Visits: 2156
replication needs an identity column create new identity column in both servers.
happycat59
happycat59
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3565 Visits: 3107
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.



keepintouch2b
keepintouch2b
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
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
happycat59
happycat59
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3565 Visits: 3107
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.



durga.palepu
durga.palepu
SSC-Enthusiastic
SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)

Group: General Forum Members
Points: 157 Visits: 220
Thank you, you saved my day Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search