Add An AUTO_INCREMENT Column As PRIMARY KEY In MySQL ...
Maybe your like
AUTO_INCREMENT for PRIMARY KEY
We can add a new column like an id, that auto increments itself for every row that is inserted to the table.
In this MySQL Tutorial, we shall create a new column that is PRIMARY KEY with AUTO_INCREMENT column modifier.
To add a new column to MySQL, following is the syntax of the SQL Query:
</> Copy ALTER TABLE table_name ADD [COLUMN] new_column_name AUTO_INCREMENT PRIMARY KEY;Example 1 – AUTO_INCREMENT for PRIMARY KEY
For this example, let us consider the following table, students.

Run the following SQL Query to add a new column named id that acts as PRIMARY KEY and auto increments for each insert.
</> Copy ALTER TABLE students ADD id INT AUTO_INCREMENT PRIMARY KEY;
The column id is added successfully. Lets see the contents of the modified table.

Let us see the updated table schema.

Tag » Add Column Id Auto Increment Mysql
-
MySQL 8.0 Reference Manual :: 13.1.9.3 ALTER TABLE Examples
-
Add Auto-Increment ID To Existing Table? - Mysql - Stack Overflow
-
How To Add Auto Increment Column In Existing Table In MySQL - Ubiq
-
SQL AUTO INCREMENT A Field - W3Schools
-
How To Add Auto-increment To Column In MySQL Database Using ...
-
MySQL: Sequences (AUTO_INCREMENT) - TechOnTheNet
-
“how To Add Auto Increment Column In Existing Table In Mysql” Code ...
-
How To Work With Auto-Incrementing IDs In SQL - Retool
-
How To Add Auto Increment Column To Existing Table - YouTube
-
AUTO_INCREMENT - MariaDB Knowledge Base
-
Working With AUTO_INCREMENT Columns In MySQL
-
AUTO_INCREMENT - PingCAP Docs
-
Sql Server - Add An Auto Increment Column By An Order Condition
-
Setting Up MySQL Auto Increment Primary Key 101 - Hevo Data