|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Primary Keys : Distributed Database : Not using GUID or Indentity columnsI would like to generate Primary Keys for tables in a *distributed* database. How has this been done before? I can't imagine that this problem has not been solved a million times, but I have been unable to find good information on how to do this. Understand that I do not wish to use Identity columns, or use a GUID for the PKs in any tables. For this example lets assume the following: 1. We have an PurchaseOrders Table that has a PONum Column. 2. We have a SalesOrders Table that has a SONum Column . Pretty simple right? To keep things simple, lets assume that we have two branch offices (there could be 2-50).Now since this database is distributed using SQL 2005 Merge replication, we need to add rows to the tables and avoid primaryKey violations. This also means that we do not contact a centralized database to get a unique key, we must generate the key at the local branch. So my first idea is to use a CHAR(n) or VARCHAR(n) encoded as: BO1SO00001 -- Branch Office #1 Sales Order Number 1 BO1SO00002 -- Branch Office #1 Sales Order Number 2 BO1SO00003 BO2SO00001 -- Branch Office #2 Sales Order Number 1 BO2SO00002 BO2SO00003 .... Another table (PO's), might be: BO1PO00001 -- Branch Office #1 Purchase Order Number 1 BO1PO00002 This would work, but then I need a Generator at each branch office. ======================================= Maybe I could encode differently by using a 3 columns and the PK would be a composite key? One column for Branch Office, CHAR(3) One column for Sales Order, CHAR(3) and another column for the sequential portion. (INT) Thanks for you input Russell Mangel Las Vegas, NV |
|||||||||||||||||||||||