Moon
Moon

Reputation: 20002

mySQL Database: Reset AutoIncrement Fields

while the development of websites we use the database to test & all... which consumes a lot from auto generated (auto increment) attributes series... how to reset everything...

Upvotes: 3

Views: 658

Answers (3)

Mike P
Mike P

Reputation: 2877

Another possibility, avoiding transactions and resetting the autoincrement counter could be to combine the select to get the next available id and the insert itself;

INSERT INTO tablename (id, somefield1, somefield2) SELECT max(id)+1, 'test', 5 FROM tablename

Upvotes: 0

ceejayoz
ceejayoz

Reputation: 179994

Assuming you're deleting the records when you're done testing, a TRUNCATE command will delete all records and reset the autoincrement value.

Upvotes: 4

Vadyus
Vadyus

Reputation: 1329

ALTER TABLE _TABLE_ AUTO_INCREMENT=1

Upvotes: 3

Related Questions