0

Hi everyone,

I have created tables and deleted some rows and then inserted new rows. The IDs of the later created rows didn't start at 0 or 1. I dropped my entire database then recreated the same one with the same tables and fields. Unfortunately, newly entered rows started from where they were left at. For example, in the previous database, I had 9 rows in users table. After the database creation, the first row started at 10 instead of starting at 0 or 1. Now, I'd like to reset the auto-increment ID. Is there a way of resetting the ID after dropping and recreating a table with the same fields ?

I tried this line but it didn't work !!

ALTER TABLE `users` AUTO_INCREMENT = 1;

Thanks, folks.

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by rotten69
0

In one of the user comments on this page it is suggested to drop your auto-inc column, and re-add it.

I'm not sure how you recreated your database, but if you did it with an sql dump, the original auto-inc may have been in the create table query. Depending on how you exported, there should be a possibility to turn that off.

0

ID is a primary key in the parent table and causes a referential integrity issue if I attempt to delete it and recreate it.

0

I'm not sure how you recreated your database, but if you did it with an sql dump,

I dropped all constraints and FKs from the tables and then dropped the database.

DROP DATABASE database_name

I noticed that this command is disabled when the DB has tables in it. So, I had to drop all tables then drop the DB.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.