mysql ID自动增量不从0开始 [英] mysql ID auto increment doesn't starts from 0

查看:997
本文介绍了mysql ID自动增量不从0开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表ID,这个ID是自动递增和主键,第一次插入到该表,ID从0开始,但是我从该表中删除所有的值,并再次插入到它, ID不从0开始,而是从ID的最后一个值开始,出现了什么错误?
可以将值重置为0?

i have a table with ID , this ID is auto increment and primary key ,the first time i inserted to that table , the ID starts from 0 , but after i removing all the values from that table and inserted again to it , the ID doesn't start from 0 , but starts from the last value that ID had , what is going wrong please ? can i reset the value to 0 ?

推荐答案

您可以使用

TRUNCATE `table`

Truncate将删除表中的所有数据。请注意,使用 TRUNCATE 也不会触发任何DELETE触发器,例如 DELETE

Truncate will delete all of the data in the table. Note that using TRUNCATE will also not fire any DELETE triggers like DELETE.

或者您可以使用

ALTER TABLE `table` AUTO_INCREMENT = 1

但是这是预期的行为。不要做后者,除非表格真的为空。

It is however the expected behavior. Don't do the latter unless the table is truly empty.

这篇关于mysql ID自动增量不从0开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆