Auto increment ID value

Asked

Viewed 234 times

1

In my Mysql Workbench I have 4 tables with auto increment id.

But when I fill out the form it adds values not followed.

For example:

I fill out a form for the first time and the ID it puts me is 3.

I want Id to be followed. Is there any way around or fix this?

  • Do you have any specific reason to start at 1, or is it just curiosity?

  • I want you to start from the beginning. because the other tables that are linked also start from the number 1

  • The first time? I think so... If you have 3 tuples in your table with id’s 2,3,4 and you delete the line with id = 4, Getting Only 2,3 when a new record is inserted, this will be the number 5. Getting that way 2,3,5. And that’s totally correct. Is that or am I making a mess? Clarify the question better...

  • You might be right. and I think so. But I tested the table on the first record and it started on 3.

2 answers

3

You can also change the value of the property if you have lost the sequence if you have removed any record.

ALTER TABLE `TABELA` AUTO_INCREMENT = ?;

In the ? you substitute for the amount you want.

If you need the data do not need to truncate only this will solve.

2

Truncate the table, it will reset auto-increment.

Note: if your table has records you don’t want to lose, make a backup first:

TRUNCATE [TABLE] tbl_name

More in the Mysql documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.