Insert after truncate start from 1; but insert after delete resumes from previous value

后端 未结 3 1224
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-28 09:07

In my table there is column name id which is auto increment integer. When I truncate table and then try to perform insert query it starts from 1, but if I do delete operation an

3条回答
  •  臣服心动
    2021-01-28 09:17

    The current max value for the autoincrement function is stored in the table definition (you can see it when you run show create table idle. When you delete all rows from the table, the autoincrement value will stay the same. When you truncate the table you basically drop the table and recreate it, which resets the the autoincrement value to 0.

    Hope this helps.

提交回复
热议问题