PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Re: Reset a auto increment field?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: Reset a auto increment field?

Réponse
 
LinkBack Outils de la discussion
Vieux 29/08/2007, 18h02   #1
dpgirago@mdanderson.org
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Reset a auto increment field?

> Is there away to reset an auto incrementing field count? I have a
> database that currently has 935 records in it but because I have
> deleted a few the current number used for NEW records is 938 How
> can I get it to count the records and assign a record number based on
> the total count?
>
> Hope that makes sense! Thanks for looking!
>
> --


> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> japruim@raoset.com


AFAIK, you need to drop and then recreate the auto-increment field,
otherwise you'll get holes when you delete a record.

David


  Réponse avec citation
Vieux 29/08/2007, 18h48   #2
emierzwa@micron.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Reset a auto increment field?

To change the value of the AUTO_INCREMENT counter to be used for new
rows, do this:

ALTER TABLE t2 AUTO_INCREMENT = value;

You cannot reset the counter to a value less than or equal to any that
have already been used. For MyISAM, if the value is less than or equal
to the maximum value currently in the AUTO_INCREMENT column, the value
is reset to the current maximum plus one. For InnoDB, you can use ALTER
TABLE ... AUTO_INCREMENT = value as of MySQL 5.0.3, but if the value is
less than the current maximum value in the column, no error message is
given and the current sequence value is not changed.


Ed

-----Original Message-----
From: dpgirago@mdanderson.org [mailto:dpgirago@mdanderson.org]
Sent: Wednesday, August 29, 2007 11:02 AM
To: Jason Pruim
Cc: MySQL List
Subject: Re: Reset a auto increment field?

> Is there away to reset an auto incrementing field count? I have a
> database that currently has 935 records in it but because I have
> deleted a few the current number used for NEW records is 938 How
> can I get it to count the records and assign a record number based on
> the total count?
>
> Hope that makes sense! Thanks for looking!
>
> --


> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> japruim@raoset.com


AFAIK, you need to drop and then recreate the auto-increment field,
otherwise you'll get holes when you delete a record.

David


  Réponse avec citation
Vieux 29/08/2007, 18h52   #3
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Reset a auto increment field?

If I understand you correctly, if my table is MyISAM, after I did a
delete query I could just: "ALTER TABLE t2 AUTO_INCREMENT="1"; and
that would cause the auto increment value to be set to 901 (Assuming
900 total current records) on the next insert?


On Aug 29, 2007, at 1:48 PM, <emierzwa@micron.com>
<emierzwa@micron.com> wrote:

> To change the value of the AUTO_INCREMENT counter to be used for new
> rows, do this:
>
> ALTER TABLE t2 AUTO_INCREMENT = value;
>
> You cannot reset the counter to a value less than or equal to any that
> have already been used. For MyISAM, if the value is less than or equal
> to the maximum value currently in the AUTO_INCREMENT column, the value
> is reset to the current maximum plus one. For InnoDB, you can use
> ALTER
> TABLE ... AUTO_INCREMENT = value as of MySQL 5.0.3, but if the
> value is
> less than the current maximum value in the column, no error message is
> given and the current sequence value is not changed.
>
>
> Ed
>
> -----Original Message-----
> From: dpgirago@mdanderson.org [mailto:dpgirago@mdanderson.org]
> Sent: Wednesday, August 29, 2007 11:02 AM
> To: Jason Pruim
> Cc: MySQL List
> Subject: Re: Reset a auto increment field?
>
>> Is there away to reset an auto incrementing field count? I have a
>> database that currently has 935 records in it but because I have
>> deleted a few the current number used for NEW records is 938 How
>> can I get it to count the records and assign a record number based on
>> the total count?
>>
>> Hope that makes sense! Thanks for looking!
>>
>> --

>
>> Jason Pruim
>> Raoset Inc.
>> Technology Manager
>> MQC Specialist
>> 3251 132nd ave
>> Holland, MI, 49424
>> www.raoset.com
>> japruim@raoset.com

>
> AFAIK, you need to drop and then recreate the auto-increment field,
> otherwise you'll get holes when you delete a record.
>
> David
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?
> unsub=japruim@raoset.com
>
>


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim@raoset.com


  Réponse avec citation
Vieux 29/08/2007, 19h19   #4
emierzwa@micron.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Reset a auto increment field?

Yes, for a MyIsam type table.

Ed

-----Original Message-----
From: Jason Pruim [mailto:japruim@raoset.com]
Sent: Wednesday, August 29, 2007 11:53 AM
To: emierzwa
Cc: dpgirago@mdanderson.org; mysql@lists.mysql.com
Subject: Re: Reset a auto increment field?

If I understand you correctly, if my table is MyISAM, after I did a
delete query I could just: "ALTER TABLE t2 AUTO_INCREMENT="1"; and
that would cause the auto increment value to be set to 901 (Assuming
900 total current records) on the next insert?


On Aug 29, 2007, at 1:48 PM, <emierzwa@micron.com>
<emierzwa@micron.com> wrote:

> To change the value of the AUTO_INCREMENT counter to be used for new
> rows, do this:
>
> ALTER TABLE t2 AUTO_INCREMENT = value;
>
> You cannot reset the counter to a value less than or equal to any that
> have already been used. For MyISAM, if the value is less than or equal
> to the maximum value currently in the AUTO_INCREMENT column, the value
> is reset to the current maximum plus one. For InnoDB, you can use
> ALTER
> TABLE ... AUTO_INCREMENT = value as of MySQL 5.0.3, but if the
> value is
> less than the current maximum value in the column, no error message is
> given and the current sequence value is not changed.
>
>
> Ed
>
> -----Original Message-----
> From: dpgirago@mdanderson.org [mailto:dpgirago@mdanderson.org]
> Sent: Wednesday, August 29, 2007 11:02 AM
> To: Jason Pruim
> Cc: MySQL List
> Subject: Re: Reset a auto increment field?
>
>> Is there away to reset an auto incrementing field count? I have a
>> database that currently has 935 records in it but because I have
>> deleted a few the current number used for NEW records is 938 How
>> can I get it to count the records and assign a record number based on
>> the total count?
>>
>> Hope that makes sense! Thanks for looking!
>>
>> --

>
>> Jason Pruim
>> Raoset Inc.
>> Technology Manager
>> MQC Specialist
>> 3251 132nd ave
>> Holland, MI, 49424
>> www.raoset.com
>> japruim@raoset.com

>
> AFAIK, you need to drop and then recreate the auto-increment field,
> otherwise you'll get holes when you delete a record.
>
> David
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?
> unsub=japruim@raoset.com
>
>


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim@raoset.com


  Réponse avec citation
Vieux 29/08/2007, 20h14   #5
Jerry Schwartz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Reset a auto increment field?

It would not reset to 901 unless the highest numbered record were 900. It
won't fill in holes.

Since autoincrement fields are typically used as keys linking to other
tables, renumbering existing records is not done often. If you REALLY want
to renumber them all, copy the records to a new table but leave off the
autoincrement field. TRUNCATE the original table and copy back the original
records, supplying NULL for the autoincrement field.

Regards,

Jerry Schwartz
The Infoshop by Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341

www.the-infoshop.com
www.giiexpress.com
www.etudes-marche.com


> -----Original Message-----
> From: Jason Pruim [mailto:japruim@raoset.com]
> Sent: Wednesday, August 29, 2007 1:53 PM
> To: emierzwa@micron.comemierzwa@micron.com
> Cc: dpgirago@mdanderson.org; mysql@lists.mysql.com
> Subject: Re: Reset a auto increment field?
>
> If I understand you correctly, if my table is MyISAM, after I did a
> delete query I could just: "ALTER TABLE t2 AUTO_INCREMENT="1"; and
> that would cause the auto increment value to be set to 901 (Assuming
> 900 total current records) on the next insert?
>
>
> On Aug 29, 2007, at 1:48 PM, <emierzwa@micron.com>
> <emierzwa@micron.com> wrote:
>
> > To change the value of the AUTO_INCREMENT counter to be

> used for new
> > rows, do this:
> >
> > ALTER TABLE t2 AUTO_INCREMENT = value;
> >
> > You cannot reset the counter to a value less than or equal

> to any that
> > have already been used. For MyISAM, if the value is less

> than or equal
> > to the maximum value currently in the AUTO_INCREMENT

> column, the value
> > is reset to the current maximum plus one. For InnoDB, you can use
> > ALTER
> > TABLE ... AUTO_INCREMENT = value as of MySQL 5.0.3, but if the
> > value is
> > less than the current maximum value in the column, no error

> message is
> > given and the current sequence value is not changed.
> >
> >
> > Ed
> >
> > -----Original Message-----
> > From: dpgirago@mdanderson.org [mailto:dpgirago@mdanderson.org]
> > Sent: Wednesday, August 29, 2007 11:02 AM
> > To: Jason Pruim
> > Cc: MySQL List
> > Subject: Re: Reset a auto increment field?
> >
> >> Is there away to reset an auto incrementing field count? I have a
> >> database that currently has 935 records in it but because I have
> >> deleted a few the current number used for NEW records is 938 How
> >> can I get it to count the records and assign a record

> number based on
> >> the total count?
> >>
> >> Hope that makes sense! Thanks for looking!
> >>
> >> --

> >
> >> Jason Pruim
> >> Raoset Inc.
> >> Technology Manager
> >> MQC Specialist
> >> 3251 132nd ave
> >> Holland, MI, 49424
> >> www.raoset.com
> >> japruim@raoset.com

> >
> > AFAIK, you need to drop and then recreate the auto-increment field,
> > otherwise you'll get holes when you delete a record.
> >
> > David
> >
> >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe: http://lists.mysql.com/mysql?
> > unsub=japruim@raoset.com
> >
> >

>
> --
>
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> japruim@raoset.com
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=j...e-infoshop.com
>
>




  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h53.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15355 seconds with 13 queries