During Transactional Replication, we have data going from Server A to Server B.
Say we were to reseed an Identity Column on a Table on Server A (for whatever reason), how would this affect the data on Server B?
My intuition would say that the data on Server A will use the newly seeded Identity, and that would be sent over to Server B as-is (and Server B would have content using the new Identity), but I'm not sure if this is correct.
Best Answer
It is always tricky when you have Identity column and that is a Primary Key for the table.
Based on my experience dealing with T-Rep and Merge, I would recommend to use
NOT FOR REPLICATION
to NO. By default it is set to YES. You can do it on sql 2005 and up dynamically (without affecting replication) usingsys.sp_identitycolumnforreplication
.If you are not updating the data on subscriber side, you should be fine.
To answer your question :
Considering, you are not updating the data on subscriber, when you want to reseed, you should always take the max value from the identity column and then reseed the value accordingly.
You can use below sql to find that out :
for example consider below customer table :
Now if you want to somehow reseed the identity value, you can run
This means that it will set the current Identity value to 8, so next time any row is inserted into the table, it will have current identity value as 8 (CurrentIdentityValue) + 1(Identity_increment) = 9.
You have to be careful doing this as this can cause identity gaps.
Other things you can do are :
sp_addaritcle
with parameters like@identity_range ,@pub_identity_range and @threshold
Read up on :