Page 1 of 1

Problem with Auto-Increment and Deleting

Posted: Mon Jul 29, 2002 9:13 am
by bedcor
When i delete a record from my MySQL database it works fine, but then when i reload the form to Insert another record, it sticks the record into the database but at the position where i deleted the record.

Can someone show me a way of keeping the autoincrement at the last record in the database even after i delete a record?

Thanx

Posted: Mon Jul 29, 2002 10:31 am
by EricS
Change your table type to MyISAM, your table is probably an ISAM.

Posted: Mon Jul 29, 2002 10:35 am
by bedcor
How do i do that?

Posted: Mon Jul 29, 2002 10:37 am
by protokol
ALTER TABLE `table_name` TYPE = MYISAM

Just replace table_name with the table you want to change

Posted: Mon Jul 29, 2002 10:39 am
by bedcor
Thanks for the help, but can you tell me the difference between the two?

Posted: Mon Jul 29, 2002 10:41 am
by Johnm
Get the highest record number from the database.
Something like:

Code: Select all

select MAX(record_number) from database_table...
save it as a variable and increment it,

Code: Select all

$max_record=$rowї'(max)'] + 1;

Then submit it as a new record to the database with the rest of the data you need to store.

Direwolf

Posted: Mon Jul 29, 2002 8:37 pm
by EricS
If you want the exact details lookup "MyISAM" and "ISAM". The short answer is that ISAM is the old table structure and MyISAM is the replacement. More features and more flexibility (like in the case where it solves your problems here!).

Posted: Wed Jul 31, 2002 5:25 am
by mikeq
Johnm wrote:Get the highest record number from the database.
Something like:

Code: Select all

select MAX(record_number) from database_table...
save it as a variable and increment it,

Code: Select all

$max_record=$rowї'(max)'] + 1;

Then submit it as a new record to the database with the rest of the data you need to store.

Direwolf
What if 2(or more) people do this at exactly the same time?