MySQL Auto-Increment Setup Guide
The steps for setting up an auto-increment ID in MySQL are as follows:
- automatically increase
CREATE TABLE table_name (
id INT AUTO_INCREMENT PRIMARY KEY,
col1 VARCHAR(50),
col2 INT
);
- Modify the table
ALTER TABLE table_name
MODIFY COLUMN id INT AUTO_INCREMENT PRIMARY KEY;
- Modify table
- Automatically increase the value
ALTER TABLE table_name
MODIFY COLUMN id INT AUTO_INCREMENT PRIMARY KEY;
- After setting up an auto-increment ID, you can test if it is working by inserting data. MySQL will automatically generate a unique ID for each new record inserted, without the need to manually specify it.