Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

First free ID ?? - please help

Status
Not open for further replies.

Xkarlos77

Programmer
Jan 19, 2003
28
0
0
CZ
Hello, I have problem:

is there any way how get the number of first free ID in a table ??

table look like this :

ID, Name, ...
1,
3,
5,
6,

Is it possible without inserting a record ???

thank you
 
actually, there is, but it involves a right join with an integer table, and setting up the integer table to have as many entries as the maximum ID is painful

also, i cannot think of any reason why you would want to find the "first free" ID, if the ID is some kind of surrogate primary key -- re-using an ID is a very very bad idea


rudy
 
Yes may be,

but when I use still new and new ID,
then the number is greater and greater
and can go over the limit of INTEGER number.

??

so deleted IDs is better not re-using ???

thanks
 
I agree with r937. Don't reuse the IDs.

In general, I recommend you use "int unsigned" rather than "int" for IDs. That will give you 4294967295 (2[sup]32[/sup]-1)records to insert before you run out of IDs.

And if you are still worried about running out of IDs, then use "bigint unsigned". This will allow you to insert 18446744073709551615 (2[sup]64[/sup]-1) records before you run out of IDs. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top