I have two same databases on two different servers: one primary and one backup. Users are currently in both servers. We have an OrderId column in tblOrder in both db’s as the auto incrementing primary key. Now when I publish the orderid to our amazon server it sometimes shows an error because the orderid on both databases are the same number and a duplicate orderid is not accepted by the system.
I want to get the max orderid from both the server and then give the new orderid to current working database. I will remove the auto incrementing seed from it, so that on insert command I will insert the orderid manually.
Solutions:
As mentioned already, you can change the increment on each identity field to 2, and have one server with a seed of 1 and the other a seed of 2.
Presuming you don’t foresee handling more than 1 billion orders on each server, simply set the seed on the second server to 1,000,000,000. No need to change the increment.
Use a
uniqueidentifier(GUID) as your primary key rather than an integer. For SQL Server 2005 and above, you can set a default constraint to NEWSEQUENTIALID() to keep inserts from constantly creating page splits.