Mysql截断表,自动增量不起作用 [英] Mysql Truncate Table, Auto Increment not working

查看:253
本文介绍了Mysql截断表,自动增量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我只是截断了我的表,但是现在我的主键不会自动递增.每次我将第二项添加到表中时,都会返回1062:键"PRIMARY"的条目"0"重复

So i just truncated my table but now my primary key will not auto increment. Every time I add a 2nd item to the table, it comes back with 1062: Duplicate entry '0' for key 'PRIMARY'

我认为,当您截断一个表时,它只会将自动增量重置为1.

I thought when you truncate a table it will just resets the auto increment back to 1.

我四处寻找可以做的事,但我遇到很多人说要截断.

I search around on what I could do but I have come across many people saying just truncate.

我做了

"TRUNCATE TABLE mytable;"

我一定做错了事.

推荐答案

此错误不影响Mysql 5.0,并且在6.0、5.1.23和5.1BK上可重复.

This bug not affects Mysql 5.0 and it is repeatable on 6.0 and 5.1.23 and 5.1BK.

请参阅此链接以获取证据

以下是随时可用的方法,有效的解决方法是在表被截断后更改autoinc的值.

Following is readily available and effective workaround is to ALTER the autoinc value after the table is truncated.

截断后立即重新初始化autoinc值

Re-initialize the autoinc value right after truncation

alter table tablename AUTO_INCREMENT = n;/*根据需要设置n */

alter table tablename AUTO_INCREMENT = n; /* set n as desired */

这篇关于Mysql截断表,自动增量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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