Jump to content

[SOLVED] question about auto increment in MySQL


webguync

Recommended Posts

Say you have a table with a field called ID set as Type(smallint), and set to auto increment. You have 10 entries, 1-10 in the ID field. You delete the entries, and start adding new ones. Even though there are currently no entries, the new additions will begin 11,12,13,14,15, and so on for the ID's. Is there a way to get the ID's to start over at 1 without manually going in to edit each one?

Say you have a table with a field called ID set as Type(smallint), and set to auto increment. You have 10 entries, 1-10 in the ID field. You delete the entries, and start adding new ones. Even though there are currently no entries, the new additions will begin 11,12,13,14,15, and so on for the ID's. Is there a way to get the ID's to start over at 1 without manually going in to edit each one?

Why does everyone want to do this?

 

This is NOT a counter.

 

This is a unique row identifier -- never to be re-used.

 

Oh, and you'll kick yourself later for using SMALLINT -- use UNSIGNED INT instead.

In round numbers

[pre]

+----------------+---------------+

|  ID TYPE      |  MAX ROWS    |

+----------------+---------------+

|  SMALLINT      |        32,000 |

|  UNSIGNED INT  | 4,000,000,000 |

+----------------+---------------+

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.