Mysql - how to set auto-increment to start from zero

前端 未结 2 1433
盖世英雄少女心
盖世英雄少女心 2020-12-16 21:34

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

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

2条回答
  •  醉梦人生
    2020-12-16 22:13

    SET [GLOBAL|SESSION] sql_mode='NO_AUTO_VALUE_ON_ZERO'
    

    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.

    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.)

    Reference

    Reference 2

提交回复
热议问题