MySQL + SQL · Lesson 40
AUTO_INCREMENT in MySQL
What is AUTO_INCREMENT?
AUTO_INCREMENT makes a column generate the next number automatically for each new row — perfect for ID/primary key columns.
Example
CREATE TABLE students (
roll_no INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50)
);
INSERT INTO students (name) VALUES ('Aman');
INSERT INTO students (name) VALUES ('Riya');
-- roll_no becomes 1, then 2 automaticallyYou never type roll_no; MySQL fills 1, 2, 3, ... by itself.
Summary
- AUTO_INCREMENT auto-generates the next number for new rows.
- Used on ID/primary-key columns so you never set them manually.