Page 1 of 1

Auto increment (MYSQL) or (PHP)

Posted: Fri Jan 02, 2009 1:29 am
by kalp1200
Hi,

What is the best way to do auto incrementing for tables in the database. The default way in the mysql database allows you to increment, but when you delete, it leaves a gap and continues with the next following number.

Q1 – Can mysql trigger herlp
Q2 - It can be done from the client side, but how do I go about it..

Re: Auto increment (MYSQL) or (PHP)

Posted: Fri Jan 02, 2009 1:37 am
by requinix
kalp1200 wrote:What is the best way to do auto incrementing for tables in the database. The default way in the mysql database allows you to increment, but when you delete, it leaves a gap and continues with the next following number.
That is the best way.

I'd quote them if I remembered where the post was, but auto_increment fields are supposed to be unique and never, ever repeated. If something gets deleted it doesn't matter: the id number was used in the past and cannot be used again.

If you need to reuse those numbers then you're doing something the wrong way.