devxlogo

Using AUTO_INCREMENT in MySQL

Using AUTO_INCREMENT in MySQL

We know that AUTO_INCREMENT is used to have a sequential value auto incremented by itself for the records that we insert.

CREATE TABLE AUTO_TABLE (ID INT NOT NULL AUTO_INCREMENT,PRIMARY KEY (ID),NAME VARCHAR (30));

Here we see that when the records are added, the values in the ID column will start with 1, 2 and so on.

In cases where there are requirements, such that the AUTO_INCREMENT values needs to start from a number of our choice or as per some criteria.

For example, if we want to start with 105, the syntax below will help:

CREATE TABLE AUTO_TABLE (ID INT NOT NULL AUTO_INCREMENT,PRIMARY KEY (ID),NAME VARCHAR (30)) AUTO_INCREMENT=105;

Notice the last line, where the initialization is 105. So, records inserted will start with 105, 106 and so on.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist