borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Importing File Names Into DB)Next Topic (Trouble writing a query) New Topic New Poll Post Reply
AndreaVB Forum : Database : how to maintain unique ID's in a database
Poster Message
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876

icon 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
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: how to maintain unique ID's in a database

quote:
bean, i appreciate your humor, but if you don't mind, not in this post...


hey, no prob just say the word and I won't post at all...


anyways...I would lock the table (usually not so desirable) OR use a time stamp or a record count to verify whether the table has been altered since the user began making changes...if it has, then check that the changes do not break normalization rules...



____________________________
Eggheads unite! You have nothing to lose but your yolks.
11-06-2003 at 07:56 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: how to maintain unique ID's in a database

i appreciate what i've heard so far, but JL...

i have thought of the server program that does the actual entry into the database... but how can i do this to work in real time?

i figured that since they are all peers, the program doing the actual adding ought to be invisible, but still, i'd like to get more info on how i can speed such a process to work real time.

and thanks, bean. i appreciate the maturity you've shown.  

____________________________
Been busy trying to take a second degree <--it's not working out...

12-06-2003 at 02:52 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: how to maintain unique ID's in a database

so, would that mean that i would have to remove my auto number field in the add forms? meaning that numbers should not be an option for the user, since the program ought to do the numbering itself, right?

that's what i think.. and perhaps it will work... i'd just have to explain that to the client.  

thansk JL... but more info will be appreciated.

____________________________
Been busy trying to take a second degree <--it's not working out...

12-06-2003 at 03:28 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: how to maintain unique ID's in a database

well... it doesn't look so appealing.. i mean the combination...

but it does seem somewhat logical... i'll see how i can develop the idea further...

thanks, JL.



____________________________
Been busy trying to take a second degree <--it's not working out...

12-06-2003 at 05:57 PM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: how to maintain unique ID's in a database

Have you used the Mutex class. I know that you can use it to control multiple apps from doing the same thing on a single pc. Maybe it can do it over a network.

18-06-2003 at 03:31 PM
View Profile Send Email to User Show All Posts | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: how to maintain unique ID's in a database

mutex class? have no idea... anylinks or info you can provide me with?  

____________________________
Been busy trying to take a second degree <--it's not working out...

19-06-2003 at 04:07 PM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: how to maintain unique ID's in a database

Have a look for Mutex Objects in the VB Help. I have it in mine


Dim MyMutex As CMutex


Set MyMutex = New CMutex

MyMutex.OpenMutex ("DownloadCheck")
MyMutex.Wait


Set MyMutex = Nothing  ' release the handle


I did not write it but its in one the programs I maintain.



[Edited by steve_w on 19-06-2003 at 04:20 PM GMT]

19-06-2003 at 04:19 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : how to maintain unique ID's in a database
Previous Topic (Importing File Names Into DB)Next Topic (Trouble writing a query) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder