Write your own Serial Assigned Key (SAK) routine.

Put a table in your database :

SAK
----------------------------
SAKID auto_increment tinyint
----------------------------
table varChar(80) not null
field varChar(80) not null
nextValue bigint
lockedBy varCar(10)
----------------------------

Now, each time you do an insert follow these steps:

1: Select the record from SAK for the table.field you want to use.
2: See if there is a value in lockedBy. If so, someone else is already using
it, wait or bail.  If not, then update the record with your userID or if in
PHP, your session number. basically anything that's unique to this client
and or session.
3: Select to see if the lockedBy field is what you put in it.  Just to make
sure you got the lock and not someone else.
4: select to get the value in nextValue
5: Update to increment the value by 1 and to remove the lock.

Now, it doesn't really take 5 steps to do this, you can combine 3 & 4. I
broke them out logically so you could see what is going on.

Also, if you are the *only* person using the database, all the locking stuff
is superfluous.

Hope this helps,

Cal
http://www.calevans.com


-----Original Message-----
From: Viken Nokhoudian [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 30, 2001 2:58 PM
To: [EMAIL PROTECTED]
Subject: Auto-Increment - how can I avoid repeating IDs?


I am using MySQL ver. 3.22.32

When a table has an auto-incrementing ID field and the last inserted
record had an ID of, say, 100, then I delete that record, the database
engine will re-use the 100 value. How can I get the engine to never
repeat an ID value to avoid corrupted data correlations?


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to