Re: Reg: auto_increment issue.
- From: "xicheng" <xicheng@xxxxxxxxx>
- Date: 28 Jan 2006 20:12:50 -0800
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
> >
.
- References:
- Reg: auto_increment issue.
- From: Dilly raja
- Re: Reg: auto_increment issue.
- From: Thomas Shinnick
- Reg: auto_increment issue.
- Prev by Date: Re: Reg: auto_increment issue.
- Next by Date: Re: Reg: auto_increment issue.
- Previous by thread: Re: Reg: auto_increment issue.
- Next by thread: Re: Reg: auto_increment issue.
- Index(es):
Relevant Pages
|
|