Gossamer Forum
Home : General : Perl Programming :

Reset auto increment field?

Quote Reply
Reset auto increment field?
Hi Folks

I've set up a database, and one field is a a record id field which is set as auto increment. I've been testing the database for a while now, and have built up a number of test records. However, I now want the database to go live, and I want to reset the field to 01. Is this possible, and how do I go about this?

Thanks.

Wil
Quote Reply
Re: [Wil] Reset auto increment field? In reply to
Quote:
I want to reset the field to 01

You mean you deleted the test records and the ID sticks at the highest number?
Quote Reply
Re: [RedRum] Reset auto increment field? In reply to
Yes.

Wil
Quote Reply
Re: [Wil] Reset auto increment field? In reply to
Yes it's strange - not sure if it's a bug or feature.....anyway.....

You may be able to do it a few ways.

Add a record so the ID column is filled in then do:

UPDATE Table_Name SET ID_Column=1

-OR-

Delete/Re-Create the column

-OR-

Delete/Re-Create the table.

One or more of those ways definitely works.

Last edited by:

RedRum: Sep 24, 2001, 3:58 AM
Quote Reply
Re: [RedRum] Reset auto increment field? In reply to
The third option obviously works. But I don't want to go down that root as I've spent quite a bit of time creating the table.

Second option won't work as it's a Primary field.

First option will definitily not work. LAST_INSERT_ID() is built into the table.

Wil

- wil
Quote Reply
Re: [Wil] Reset auto increment field? In reply to
Re: 3rd option.....you can just dump the structure using MySQLMan and delete the table and just run the table structure through the monitor and it will be re-created the same as it was.

Last edited by:

RedRum: Sep 24, 2001, 3:58 AM
Quote Reply
Re: [RedRum] Reset auto increment field? In reply to
Yes, I assume that would work. However, I wanted to find out if there was an actual way of resetting this field without having to destroy your database. Or once set, is it hard coded into your table?

Thanks

Wil

- wil
Quote Reply
Re: [Wil] Reset auto increment field? In reply to
I wouldn't call removing one table destroying your database :)

I don't know of another way to do it. I'm sure there is a better way though as someone will probably point out.


Quote Reply
Re: [Wil] Reset auto increment field? In reply to
I don't know if the following tutorial will help:

http://www.mysql.com/...ql++/4_Tutorial.html

But it looks like the reset-db function may be able to
allow you to reset the ID field.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [AnthroRules] Reset auto increment field? In reply to
Thanks, Eliot.

Wil