Auto Incrementing primary key

Using MySQL work bench where the table has an auto generated and auto incremented primary key. Now it increments from the last key by 1:

next-key = last-key +1

I wold like to increment this number by 100:

next-key = last-key + 100

Is there a way to do this in workbench? For the column where the primary key is, there is an option to put in a default expression, if this is where it's done what would the expression look like.

A sample would be helpful.

Upvotes: 0

Views: 92

Answers (2)

You can simply set the starting value to 100 as follows

ALTER TABLE table_name AUTO_INCREMENT = 100;

But to increment this number by 100, You need to edit the global variable - auto_increment_increment in your mysql server.

https://dev.mysql.com/doc/refman/5.7/en/replication-options-master.html#sysvar_auto_increment_increment

But this change will effect all the tables in your database server.

Upvotes: 0

Hexxefir
Hexxefir

Reputation: 1810

You can do that at the creation of your table or after by a ALTER TABLE.

ALTER TABLE tbl AUTO_INCREMENT = 100;

Ref. MySQL guide: https://dev.mysql.com/doc/refman/5.7/en/example-auto-increment.html

Upvotes: 1

Related Questions