Languages
[Edit]
EN

MySQL - Create table with AUTO_INCREMENT field

0 points
Created by:
Lia-Perez
565

In this article, we would like to show you how to create table with AUTO_INCREMENT field in MySQL.

Quick solution:

Note:

Go to the official documentation to see available DATA_TYPES.

Practical example

Edit

In this example, we create users table with auto-increment id column which is also the PRIMARY_KEY field.

Note:

AUTO INCREMENT field is often the PRIMARY KEY field.

Query:

Result:

MySQL - create table with AUTO_INCREMENT field result
MySQL - create table with AUTO_INCREMENT field result

Now, when we insert into the table, we don't need to specify the id column, it will be added automatically based on the previous number.

Query:

Result:

MySQL - INSERT INTO AUTO_INCREMENT field - result
MySQL - INSERT INTO AUTO_INCREMENT field - result

References

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

MySQL - Problems

MySQL - Create table with AUTO_INCREMENT field
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join