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.
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.