MySQL从表中删除所有行并将ID重置为零 [英] MySQL Delete all rows from table and reset ID to zero

查看:222
本文介绍了MySQL从表中删除所有行并将ID重置为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除表中的所有行,但是当我添加新行时,我希望具有自动增量的主键ID分别从0开始从1开始.

I need to delete all rows from a table but when I add a new row, I want the primary key ID, which has an auto increment, to start again from 0 respectively from 1.

推荐答案

请勿删除,请使用截断:

Do not delete, use truncate:

Truncate table XXX

表处理程序不记得上一次使用的AUTO_INCREMENT值,而是从头开始计数.即使对于通常不重用序列值的MyISAM和InnoDB,也是如此.

The table handler does not remember the last used AUTO_INCREMENT value, but starts counting from the beginning. This is true even for MyISAM and InnoDB, which normally do not reuse sequence values.

.

这篇关于MySQL从表中删除所有行并将ID重置为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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