 |
|
 |
vbgen Level: Moderator
 Registered: 10-10-2002 Posts: 876
|
how to maintain unique ID's in a database
here it is... i thought i should place this at the network board, but i'm thinking, basically, i am asking for something more related to database stuff...
let's say i have a peer to peer network, and one of these terminals has the database in it, and the executable as well, all accessed by other terminals(none of the peers have a copy of the exe nor the db). there is no problem with the network connection, or even with the other terminals accessing the database.
the situation:
two terminals are trying to add an employee entry into the database, and from the prgram, they both have an id of 10001, for example.
now, they would both click the save button, and both should be saved inside the main database. (do not think of other factors like: maybe processor spee is different, maybe they didn't hit the save button at the exact same time and the like)
the id should be unique, like a primary key.
how can this be solved? should it be something connected to the idea of disconnection of a program to a database unless it needs access? whatever....
it just crossed my mind, and i would like to receive ideas and any help from others.
bean, i appreciate your humor, but if you don't mind, not in this post...
i'm sorry... it just occurd to me that i might have to face this porblem in the near future, so i oughtta ask about it this early.
thanks everyone.
____________________________
Been busy trying to take a second degree <--it's not working out...
|
|
11-06-2003 at 07:35 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: how to maintain unique ID's in a database
If you don't want to have it as a primary key, or define it as unique...
1) Query the DB for the record, then add.
2) Have a table for all users currently connected, and what number they'll use for the next entry; query that table and the main table to make sure there's no conflict
3) Have a "temporary" table that stores all entries, then a timed "server" program that does the actual entry, changing ID's if needed (of course if the ID's given to the client for references, you'll need a CLIENT ID, and DB ID)
4) Have the ID field not be an auto increment field
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
11-06-2003 at 07:56 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: how to maintain unique ID's in a database
On SQL I'd say a trigger that runs the program as soon as the table's modified...
In Access...
Can't think of a good way right now...well that wouldn't be extremely complex.
If you didn't need the "actual real" id's in display real-time, you could have the program do a query adding records from both the "final" table and the "temp" table.
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
12-06-2003 at 03:02 AM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: how to maintain unique ID's in a database
Thinking a few ways actually, but one being the computer assigns the numbers and the clients not even touching it.
Of course would the option exist to do say:
Unique ID
-----------
Micro837
Rodg920
Meaning that the unique number be a combination first x characters of the client name followed by a number? that way it'd be virtually impossible for a duplicate to be entered (especially if you pick a random large number). Client name either being that of the data entry person, or of the company that the data applies for (say if it's a company that does business with numerous other companies).
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
12-06-2003 at 06:19 AM |
|
|
|
|
 |
 |