• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

Reindex MySql table

I have a MySql table with an auto-increment id field, and in the table I have 4 records that do not change and have ids 1 to 10. The table also contain another 20+ records with id's eg 11-31. The last 20 records will be regularly deleted and re-iniserted with slightly different data, is there anyway of resetting the autoincrement back to the last record id+1, using Php without creating a new table?
0
ncw
Asked:
ncw
  • 2
  • 2
  • 2
1 Solution
 
Lukasz ChmielewskiCommented:
0
 
ncwAuthor Commented:
This option from your link could be usefull:

ALTER TABLE tbl AUTO_INCREMENT = 100;
0
 
Lukasz ChmielewskiCommented:
Should reset the autoincrement

    $q = "alter table test AUTO_INCREMENT = 2";
    $r = mysql_query($q);
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
johanntagleCommented:
Deleted and reinserted with slightly different data?  So why not just update the rows instead of all that trouble?
0
 
ncwAuthor Commented:
Deleting and reinserting data causes the id to start at the next auto-incremented id unless you recreate the table or alter the auto-increment start value, as far as I know.
0
 
johanntagleCommented:
Deleting and reinserting data causes the id to start at the next auto-incremented id unless you recreate the table or alter the auto-increment start value, as far as I know.

Exactly.  My point is, why delete and reinsert at all when you can just update the rows to reflect the slightly different data?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now