MySQL-如何将自动增量设置为从零开始 [英] Mysql - how to set auto-increment to start from zero

查看:107
本文介绍了MySQL-如何将自动增量设置为从零开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只希望我的mysql表ID(主键)从0开始..

I just want my mysql table id(primary key) to start from 0..

正如我所看到的,我使用ALTER TABLE yourtable AUTO_INCREMENT = 0,但是它从1开始.我需要做什么?

As I have seen, I used ALTER TABLE yourtable AUTO_INCREMENT =0 but it starts from 1..What is that I need to do?

Edit1

我也用truncate选项清空了表

I also emptied my table with truncate option

推荐答案

SET [GLOBAL|SESSION] sql_mode='NO_AUTO_VALUE_ON_ZERO'

NO_AUTO_VALUE_ON_ZERO影响AUTO_INCREMENT列的处理.通常,您可以通过在该列中插入NULL或0来为该列生成下一个序列号. NO_AUTO_VALUE_ON_ZERO将此行为抑制为0,以便只有NULL才能生成下一个序列号.

NO_AUTO_VALUE_ON_ZERO affects handling of AUTO_INCREMENT columns. Normally, you generate the next sequence number for the column by inserting either NULL or 0 into it. NO_AUTO_VALUE_ON_ZERO suppresses this behavior for 0 so that only NULL generates the next sequence number.

如果在表的AUTO_INCREMENT列中存储了0,则此模式很有用. (顺便说一句,建议不要存储0.)

This mode can be useful if 0 has been stored in a table's AUTO_INCREMENT column. (Storing 0 is not a recommended practice, by the way.)

参考

参考2

这篇关于MySQL-如何将自动增量设置为从零开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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