Re: MySQL auto_increment ??
| From: | Jakob Kruse | Date: | Sun, 10 Mar 2002 01:36:28 +0000 |
| Subject: | Re: MySQL auto_increment ?? | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-12555@lists.php.net to get a copy of this message | ||
"Sviss Cobazor" <sviss@nospam.dk> wrote:
> Hi NG.
>
> Now I've read page up and page down in the MySQL online manual about how
to
> use the auto_increment. But I didn't find anywhere how to reuse a deleted
id
> created by auto_increment.
>
> Say I have a table [users] with 4 columns:
>
> | ID | name | username | password |
>
> ID is an auto_increment value.
> If I insert 3 users they will get ID = 1, 2 and 3 assignet.
> Now I want to delete user with ID = 2.
> Now I create a new user, he will get ID = 4.
>
> How can i reuse the ID 2 for creation of new users?
Just assign the value 2 to the ID field when creating or saving a user. When
the value is NULL, the auto_increment feature will be used, and it will only
reassign values if you reset the auto_increment counter (not recemmended).
> Another thing:
> If ID is INT(3), what will happen when I insert user no. 1000?
It will work as expected. An INT(3) is not limited to 3 digits, it just
displays values with 3 digits minimum. An unsigned INT can be as large as
4294967295.