We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,001 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Auto_increment

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.

3
Contributors
3
Replies
18 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
manaila
Light Poster
43 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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;
pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

I emptied it using the query: DELETE FROM persons;

manaila
Light Poster
43 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9
Question Answered as of 1 Year Ago by pritaeas and hericles

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0942 seconds using 2.7MB