Re: Reg: auto_increment issue.



Thomas Shinnick wrote:
> > I created a table in mysql in which i set a field "id" in that table to
> > auto_increment and this field is the primary key to this tabel. so each
> > time a new record is added the id increment by 1. When i delete a last
> > record and insert the next record it increment the value from the deleted
> > record only instead of the last existing record. Is there any solution in
> > which i can set these values or reset the auto_increment so that it starts
> > from the first when i delete all the record.
>
> Using Google and "mysql auto-increment reset dbi" I found:
>
> On this page http://www.debian-administration.org/articles/64
> To reset the autoincrement values of your table run:
> truncate table TABLENAME
> This will cause the id to start from zero again.
By truncating the table, you actually delete all records in the table
and just keep the structure of the table, I guess this is not OP's
original requirement.

For MyISAM and InnoDB tables, these AUTO_INCREMENT values are not
supposed to be reused, this way, you can be guarenteed to keep a column
with monotonic sequences. You may reuse by altering your table to ISAM
or BDB, but I guess that's not really what you wanted. Be careful, *NO*
TRUNCATE unless you dont need your data any more..

Xicheng
>
> Over at MySQL.COM I find things like
> 3.6.9. Using AUTO_INCREMENT
> To start with an AUTO_INCREMENT value other than 1, you can set
> that value with CREATE TABLE or ALTER TABLE, like this:
> mysql> ALTER TABLE tbl AUTO_INCREMENT = 100;
> Note that this feature is available for InnoDB tables only as
> of MySQL 4.1.12.
>
> You might want to look around in the MySQL manual to see where they
> describe exactly how the auto-increment 'counter' is set by MySQL.
>
> I hope one of the above two ideas helps you, and Google is always helpful.
> (If my books weren't packed I'd look this up in my "MySQL Cookbook" book)
>
> > --
> > Friendly,
> > Raja.M
> >

.



Relevant Pages

  • Re: How does one start mysql after installing from ports
    ... installed mysql a few weeks ago on this web server I'm making for my ... I eventually figured out that the mysqld process starts by using ... InnoDB: The error means mysqld does not have the access rights to ... InnoDB: File operation call: 'create'. ...
    (freebsd-questions)
  • Re: MySQL config [WAS: ]uilding a new workstation - dual or quad-core CPU for FreeBSD 7?
    ... flaw in how mysql handles non-zero concurrency values here (innodb ... check if it should try to allow more innodb concurrency. ... instead of being bottlenecked by disk speeds and leaving the CPUs mostly ... We should probably submit a bug to MySQL rather then add a patch to ...
    (freebsd-questions)
  • Re: Frage zu Distinct/GroupBy (?)
    ... und MySQL gar keine Rückmeldung gibt... ... Zum Thema Index: Ich hatte mit den Indizes ein wenig rumgespielt. ... DROP TABLE IF EXISTS `tabelle`; ... Bei mir ist InnoDB als Defaulttabelentyp eingestellt - ich kann mich nur mit Tipaufwand dagegen wehren und dafür war mir die Zeit zu schade. ...
    (de.comp.datenbanken.mysql)
  • Re: Problem with mysql-server.sh script (5.0.18 on 6.1-PRE)
    ... I suppose the owner of /var/db/mysql is not mysql. ... InnoDB: a new database to be created! ... Will mysqld use /etc/hosts to resolve a hostname to bind to? ...
    (freebsd-questions)
  • Re: MySQL: Cant open and lock privilege tables: Cant find file: host
    ... On Sunday 16 April 2006 11:50 am, Pierre Sarrazin wrote: ... to have triggered an automatic upgrade from MySQL 4 to 5. ... InnoDB: Starting crash recovery. ... log sequence number 0 1302290. ...
    (Fedora)