Database Management
MySQL
Subjective
Oct 01, 2025
Explain AUTO_INCREMENT in MySQL with an example.
Detailed Explanation
AUTO_INCREMENT automatically generates unique sequential numbers for new records.
Features:
• Starts from 1 by default
• Increments by 1 for each new row
• Only one AUTO_INCREMENT column per table
• Must be indexed (usually PRIMARY KEY)
Example:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100)
);
INSERT INTO users (name) VALUES ('John'); -- id = 1
INSERT INTO users (name) VALUES ('Jane'); -- id = 2
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts