1,105,625 Community Members

Auto_increment

Member Avatar
manaila
Junior Poster in Training
50 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have a MySQL table table with two fields: id and name. id is primary key with auto_increment. The thing is when I insert a record and then empty the table, and insert a record again, the id value does not start from 1, it keeps increasing even though the table was emptied.
How can I make the id valued to start from 1 after emptying the table.

Member Avatar
pritaeas
mod_pritaeas
11,332 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
1
 

How do you empty the table, with a tool, or with a query? Your tool should have an option to do that, for the query:

ALTER TABLE `table` AUTO_INCREMENT = 1;
Member Avatar
manaila
Junior Poster in Training
50 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I emptied it using the query: DELETE FROM persons;

Member Avatar
hericles
Veteran Poster
1,078 posts since Nov 2007
Reputation Points: 98 [?]
Q&As Helped to Solve: 232 [?]
Skill Endorsements: 14 [?]
Featured
 
1
 

TRUNCATE persons; will clear out the table and reset the auto_increment primary key to zero.

Question Answered as of 2 Years Ago by pritaeas and hericles
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article