MySQL Auto-Increment Setup Guide

The steps for setting up an auto-increment ID in MySQL are as follows:

  1. automatically increase
CREATE TABLE table_name (
    id INT AUTO_INCREMENT PRIMARY KEY,
    col1 VARCHAR(50),
    col2 INT
);
  1. Modify the table
ALTER TABLE table_name
MODIFY COLUMN id INT AUTO_INCREMENT PRIMARY KEY;
  1. Modify table
  2. Automatically increase the value
ALTER TABLE table_name
MODIFY COLUMN id INT AUTO_INCREMENT PRIMARY KEY;
  1. 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.
bannerAds