You get a bonus - 1 coin for daily activity. Now you have 1 coin

MySQL: how to set AUTO_INCREMENT to start from a value other than 1

Practice



By default, when you create a table in MySQL with the AUTO_INCR EMENT column attribute, the count starts from 1. I.e. the first record created will have index 1, the second - 2, etc.

However, sometimes (really rarely) you need to force MySQL to start the AUTO_INCRE MENT count not from 1, but from another number.

The following construction is used for this:

AUTO_INCRE MENT = 100

In the example above we tell the DBMS to start counting from 100, not from 1.

Here's an example of creating a table with auto_increment = 500:

CR EATE TAB LE mytable
(id INT NOT NUL L AUTO_IN CREMENT = 500,
title VARC HAR(255) NOT N ULL DEF AULT ,
address VAR CHAR(255) NOT NU LL DE FAULT , PRIM ARY KEY(id));
Applies to: MySQL 5.x+

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - MySql (Maria DB)"

Terms: Databases - MySql (Maria DB)