Hi Mike:

Instead off delete a record, i would put a status field to indicate that
the record is deleted, and create a function that returns the key of the
first record with the deleted status for reuse, and in case that there
is no record to reuse, to create a new one and return that key.

But you will need to add a index to speed things up.

Osvaldo Sommer

-----Original Message-----
From: Mike [mailto:[EMAIL PROTECTED] 
Sent: Sunday, September 19, 2004 2:59 PM
To: [EMAIL PROTECTED]
Subject: auto increment fields

hi.
I have a rather childish question on tables and auto increment fields.
Scenario: I have a table with an <int auto increment primary key> field.
The
deal is that everything works fine (I'm talking about the auto 
incrementation part)
until I choose to delete a row. This creates a gap in the primary key
field.
And my question is: I'd like to know if there is an easier way to keep
track
of these gaps, instead of specifically iterating through the table and
stopping where you find one. To accomplish this, I use this function:

function GetUntakenNrCrt($tabel) {
 $nrCrt = 1;
 while(1>0) {
  if(!GetSingle("select nrcrt from $tabel where nrcrt='$nrCrt'")) return

$nrCrt;
  $nrCrt++;
 }
}

function GetSingle($query) {
 $q = mysql_query($query);
 if(mysql_num_rows($q) > 0)
  while($p = mysql_fetch_row($q)) return $p[0];
 else return false;
}

The reason is that I want a table with continous records in the primary
key
field (1, 2, 3... instead of 1,6,23...).
Can anyone suggest a different (and easier) method? Thanx a lot! 



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 9/17/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 9/17/2004
 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to