NIPP, SCOTT V (SBCSI) wrote:

        I have a table that has a list of users with numeric user IDs.
The user IDs are not sequential.  There are large gaps in the list of
numeric IDs.  I want to pick the next unused number beginning at 3000.

I'd use an autoincrement column for ID so you don't have to know what the next available one is.


For instance:
If you use SQL to find the last ID and then add 1 to it, say its 3001, what happens if someone else inserts a record for 3001 right befor eyou do? You'll over write her last INSERT statement.


This isn't really a perl question though...

I'd see your DB vendor's website about Auto increment columns and , like mysql has, LAST_INSERT_ID() function so you can do an insert then find out what its ID was.


Now if you really need to find it you'd need to do a query like:

 SELECT uid FROM Users LIMIT 1 ORDER BY uid;

That will give you the last uid, you can add DESC or something similar to reverse the results. But you'd need to see your DB vendor's website for more details.

HTH :)

Lee.M - JupiterHost.Net

Reply via email to