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 automatically
You 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.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp