List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:May 13 2003 2:26am
Subject:Re: how do I reset an auto_increment index to match the number of records in the DB
View as plain text  
At 7:55 -0600 6/30/01, patrick wrote:
>Ok could some kind soul point me to the doc's for reseting the index
>after deleting a few records below is my database and I did a
>delete where rec >0 and it worked however the index is still at 6 how
>can I correct this or reset the index to the number of records in the
>data base hummmmm...

You can't.  Suppose you insert six records and end up with values 1 through
6.  Now you delete records 1 through 3, leaving records with values
4 through 6.

There are three records left, but you cannot reset the sequence to
continue with the value 4, because that value is already present in
the column.

If what you mean is that you want to reset the sequence to begin
with the value one greater than the maximum value currently present
in the column, then:

1) Ask yourself why you want to do this, because it's rarely if ever
necessary to do so
2) If you convince yourself it's really necessary, then use this
statement:

ALTER TABLE tbl_name AUTO_INCREMENT = 0

Works for MyISAM tables.

>
>Thanks for the help
>going to try the doc's again :)


-- 
Paul DuBois
http://www.kitebird.com/
sql, query
Thread
how do I reset an auto_increment index to match the number of records in the DBpatrick30 Jun
  • Re: how do I reset an auto_increment index to match the number of records in the DBPaul DuBois14 May