0
0
SQLquery~10 mins

AUTO_INCREMENT behavior in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a table with an auto-incrementing primary key.

SQL
CREATE TABLE users (id INT [1] PRIMARY KEY, name VARCHAR(50));
Drag options to blanks, or click blank then click option'
AVARCHAR(10)
BAUTO_INCREMENT
CINTEGER
DPRIMARY KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using just INTEGER without AUTO_INCREMENT.
Putting PRIMARY KEY twice.
Using VARCHAR for an auto-incrementing number.
2fill in blank
medium

Complete the code to insert a new user without specifying the auto-increment column.

SQL
INSERT INTO users (name) VALUES ([1]);
Drag options to blanks, or click blank then click option'
ANULL
B1
C'Alice'
D'id'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to insert a value for the auto-increment column.
Using NULL instead of a name string.
Inserting the column name instead of a value.
3fill in blank
hard

Fix the error in the code to reset the auto-increment counter to 1.

SQL
ALTER TABLE users [1] = 1;
Drag options to blanks, or click blank then click option'
AAUTO_INCREMENT
BRESTART
CINCREMENT
DRESET
Attempts:
3 left
💡 Hint
Common Mistakes
Using RESET or RESTART which are not valid keywords here.
Trying to use INCREMENT instead of AUTO_INCREMENT.
4fill in blank
hard

Fill both blanks to create a table where the auto-increment starts at 1000.

SQL
CREATE TABLE orders (order_id INT [1] PRIMARY KEY) [2];
Drag options to blanks, or click blank then click option'
AAUTO_INCREMENT
BSTART WITH 1000
CAUTO_INCREMENT=1000
DINCREMENT BY 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'START WITH' or 'INCREMENT BY 10' which are not valid in this SQL dialect.
Putting the starting value inside the column definition.
5fill in blank
hard

Fill in the blanks to select the next auto-increment value, insert a new row, and then get the last inserted id.

SQL
SELECT [1] FROM information_schema.tables WHERE table_name = 'users';
INSERT INTO users (name) VALUES ('Bob');
SELECT [2]();
Drag options to blanks, or click blank then click option'
AAUTO_INCREMENT
BLAST_INSERT_ID
DMAX(id)
Attempts:
3 left
💡 Hint
Common Mistakes
Using MAX(id) instead of LAST_INSERT_ID() to get the last inserted id.
Confusing AUTO_INCREMENT keyword with function names.