can autoincrement field be bring back to 0 or 1?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

can autoincrement field be bring back to 0 or 1?

Post by saumya »

well, i have a mysql table.I have one autoincrement field in it.While trying all my php codes i tried putting values into the table and evrything worked fine.But when it came to do it again, i removed all the datas from table through PhpmyAdmin.Next time i put values in my databse everything worked properly but the autoincrement field does not came back to 0.It just started counting from where it was preveously before deletion of the datas.
Is there anyway to reset it back to 0?
thanks
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

1. Second Last option (on top) for a table - marked in Red - Empty - click on it and it'll delete all rows from your table and reset all counters - autoincrement to 1.

2. Third Last option (on top) - Operations - most probably last field on page - auto_increment - fill in the text box to whatever number you want.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

oooooooohoooooooooooooohoooooooooooooooooo
that worked.
thank you very much
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post by Jean-Yves »

In code, you can issue the following statement:

Code: Select all

TRUNCATE TABLE table_name
Note that this will Empty the table, and reset the autoincrement index to 1, but *only* on supported versions of MySQL and supported versions of certain table types.

See the TRUNCATE Syntax Entry in the online MySQL manual


.
crazycaddy
Forum Commoner
Posts: 43
Joined: Fri Aug 05, 2005 6:59 am
Location: England, UK

Post by crazycaddy »

Hey, I needed a solution to this too, ive been deleting my table each time and redoing it :x
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

feyd wrote:

Code: Select all

ALTER TABLE `table_name` AUTO_INCREMENT = XXX
switch out XXX for the new value you wish, if the PK used that slot, I believe it'll reset to 1 past the max you have.
Post Reply