id PRIMARY KEY, AUTO_INCREMENT starting from 1

Asked

Viewed 58 times

0

I’m having a doubt, a stupid problem. Before to carry out this code:

CREATE TABLE tabela (
    id int AUTO_INCREMENT,
    title varchar(50),
    descricao varchar(100),
    PRIMARY KEY (id)
);

when putting the first element id started at 0. But for some reason, out of nowhere now it is starting at 1, wanted to know what happened and if you have how to make it start from 0.

thank you in advance

1 answer

0

Even deleting the table data if I’m not mistaken it reset auto increment, I think this should help:

ALTER TABLE NmTabela AUTO_INCREMENT = 0
  • Didn’t work :(

  • From the manual: "Note: ALTER TABLE ... AUTO_INCREMENT = N can only change the auto-increment counter value to a value Larger than the Current Maximum." https://dev.mysql.com/doc/refman/8.0/en/innodb-auto-increment-handling.html#innodb-auto-increment-initialization

  • In the tbm documentation there is this part: "For example, you Might Try to set the counter value to a Lesser value after deleting some Records. In this case, the table must be searched to ensure that the new counter value is not Less than or Equal to the current Current Maximum counter value." :/

Browser other questions tagged

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