Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto_increment

Status
Not open for further replies.

tzzdvd

Programmer
Aug 17, 2001
52
IT
Hi,
I am a beginner in mysql&php and i have a little question:
I create a table with a field "index" created auto_increment. In fact, whenever I add a row index is incremented automatically. Here is the problem:
For example I have 10 rows.
If I delete the 10th and then I add another row, "index" of the last added row is 11 and not 10 as I wish.
Is there an automatic way to reorder the auto_increment field or have I to reorder it by myself?

Thank's for all and Happy Easter to everybody in the forum

Davide
 
Ideally the number of the index should not matter. Auto_increment is a way of ensuring each row will be unique, and though not specifically designed as a "index" field it is quite often used as such.

Rather, give each record a unique id.

$id = uniqid("");
more on this can be found here:


Use the id as your primary/foreign key for linking tables.
This way the auto_increment field can be anything and you don't care.
 
ANyway, if you want to delete all rows and restart autoincrement field use TRUNCATE instruction:

Connect to mysql server (/mysqlpath/bin/mysql ) select database (use database) and "TRUNCATE db"
.... more or less....


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top