简体   繁体   中英

how to set default autoincrement value in mysql 8

I have users table which autoincremented id automatically increased to high amount like 996165754 and I want to set autoincrement default value should start from 1260

在此处输入图片说明

how can I fix it?

MySQL's auto-increment mechanism will not generate values lower than the max id value.

You can insert lower values if you specify them yourself, but you can't get auto-increment to make one. It will always generate a value at least one greater than the highest existing value.

You can try ALTER TABLE mytable AUTO_INCREMENT=1260 but you will find it automatically raises to max(id)+1 even if you specify a lower value.

Your only solution is to eliminate the high values, either by deleting the rows or changing their id values, and then ALTER TABLE to reset the next auto-increment value.

There is no any reason to alter this value. Autoincremented primary key column must be used for referential and integrity checking purposes exclusively. In general nobody must affect it, and even there is no reason to see it. It's not meant for you.

If you need a column with small numbers - then create one more column for this purposes and fill it with the values which you need. Or enumerate rows in a query.

You cannot set autoincrement autoassigned values to a value less than maximal value already present in a table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM