0
0
MySQLquery~5 mins

AUTO_INCREMENT behavior in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the AUTO_INCREMENT attribute do in MySQL?
It automatically generates a unique number for a column when a new row is inserted, usually used for primary keys.
Click to reveal answer
intermediate
Can you manually insert a value into an AUTO_INCREMENT column?
Yes, you can insert a specific value manually, but it must not conflict with existing values or the next auto-generated value.
Click to reveal answer
intermediate
What happens if you delete the last row with the highest AUTO_INCREMENT value?
The AUTO_INCREMENT counter does not decrease automatically; new inserts continue from the last highest value plus one.
Click to reveal answer
advanced
How can you reset the AUTO_INCREMENT counter in MySQL?
You can reset it using the command: ALTER TABLE table_name AUTO_INCREMENT = value; where value is the new starting number.
Click to reveal answer
advanced
Does AUTO_INCREMENT guarantee no gaps in the sequence of generated numbers?
No, gaps can occur due to deleted rows or rolled-back transactions, so AUTO_INCREMENT values are unique but not always consecutive.
Click to reveal answer
What is the default behavior of AUTO_INCREMENT in MySQL when inserting a new row?
AIt assigns the next available unique number automatically.
BIt requires you to provide a number manually.
CIt assigns a random number.
DIt assigns NULL.
If you delete the row with the highest AUTO_INCREMENT value, what happens to the next inserted row's AUTO_INCREMENT value?
AIt throws an error.
BIt reuses the deleted row's number.
CIt resets to 1.
DIt continues from the last highest value plus one.
How do you reset the AUTO_INCREMENT counter to start from 100 in a table named 'users'?
AALTER TABLE users AUTO_INCREMENT = 100;
BRESET AUTO_INCREMENT users TO 100;
CSET AUTO_INCREMENT users = 100;
DUPDATE users SET AUTO_INCREMENT = 100;
Can AUTO_INCREMENT columns have gaps in their sequence?
ANo, they are always consecutive.
BOnly if you manually insert values.
CYes, gaps can occur due to deletions or rollbacks.
DOnly if the table is corrupted.
Which data type is commonly used with AUTO_INCREMENT columns?
ATEXT
BINTEGER
CVARCHAR
DDATE
Explain how AUTO_INCREMENT works in MySQL and what happens when rows are deleted.
Think about how MySQL keeps track of the next number to assign.
You got /4 concepts.
    Describe how to reset the AUTO_INCREMENT value and why you might want to do that.
    Consider the SQL command that changes table structure.
    You got /3 concepts.