Re: mysql ID's
| From: | Tomas Garcia Ferrari | Date: | Mon, 15 Oct 2001 14:31:20 +0000 |
| Subject: | Re: mysql ID's | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-13333@lists.php.net to get a copy of this message | ||
> I am trying to make it so that when i create a row with user details one of
> the columns is automatically generated with the next id. for example p00001,
> p00002 etc etc. I am fairly new to PHP, MySQL so bare with me :)
As I understand your question, the answer is "AUTO_INCREMENT".
I extracted this from <http://www.mysql.com/doc/C/R/CREATE_TABLE.html>
---
> An integer column may have the additional attribute AUTO_INCREMENT. When you
> insert a value of NULL (recommended) or 0 into an AUTO_INCREMENT column, the
> column is set to value+1, where value is the largest value for the column
> currently in the table. AUTO_INCREMENT sequences begin with 1. See section
> 8.4.3.126 mysql_insert_id(). If you delete the row containing the maximum
> value for an AUTO_INCREMENT column, the value will be reused with an ISAM, or
> BDB table but not with a MyISAM or InnoDB table. If you delete all rows in the
> table with DELETE FROM table_name (without a WHERE) in AUTOCOMMIT mode, the
> sequence starts over for all table types. NOTE: There can be only one
> AUTO_INCREMENT column per table, and it must be indexed.
---
Regards,
Tomás
+-- --+
Tomás García Ferrari
Bigital
http://bigital.com/
+-- --+