How do I change the amount auto_increment
fields in MySQL increment by from the default (1) to n?
In MySQL, the syntax to reset the AUTO_INCREMENT column using the ALTER TABLE statement is: ALTER TABLE table_name AUTO_INCREMENT = value; table_name. The name of the table whose AUTO_INCREMENT column you wish to reset.
Syntax for AccessBy default, the starting value for AUTOINCREMENT is 1, and it will increment by 1 for each new record. Tip: To specify that the "Personid" column should start at value 10 and increment by 5, change the autoincrement to AUTOINCREMENT(10,5) .
In MySQL, the syntax to change the starting value for an AUTO_INCREMENT column using the ALTER TABLE statement is: ALTER TABLE table_name AUTO_INCREMENT = start_value; table_name. The name of the table whose AUTO_INCREMENT value you wish to change.
ALTER TABLE Inventory MODIFY COLUMN item_number INT AUTO_INCREMENT=50; After running this code, future item IDs will start at an item_number of 50 and increment by 1. To change the starting increment value and increment in SQL Server, set your non-default values during table creation.
If you want to change autoincrement step from 1 to N then there is a solution.
It could be done on MySQL server side:
look for '--auto-increment-increment' startup option or use following command SET @@auto_increment_increment=2;
, but be warned that this is a server wide change (all tables will increment by 2).
Unortodox solutions could that could be considered:
auto_increment_increment=1
other with auto_increment_increment=2
)auto_increment
to manually calculate (simple peek at last id and +=2 would be ok) and provide id in INSERT
query.Some official MySQL FAQ
You can change it using ALTER TABLE
:
ALTER TABLE table AUTO_INCREMENT = n;
Or if you want to do set it from start:
CREATE TABLE table (...) AUTO_INCREMENT = n;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With