0
0
MySQLquery~10 mins

AUTO_INCREMENT behavior in MySQL - 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.

MySQL
CREATE TABLE users (id INT [1] PRIMARY KEY, name VARCHAR(100));
Drag options to blanks, or click blank then click option'
AAUTO_INCREMENT
BNOT NULL
CUNIQUE
DDEFAULT 0
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOT NULL instead of AUTO_INCREMENT will not auto-generate values.
Forgetting to set the column as PRIMARY KEY with AUTO_INCREMENT.
2fill in blank
medium

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

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

Fix the error in the insert statement to let auto-increment work correctly.

MySQL
INSERT INTO users (id, name) VALUES ([1], 'Bob');
Drag options to blanks, or click blank then click option'
A0
BNULL
CDEFAULT
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Inserting a fixed number instead of NULL for the auto-increment column.
Using DEFAULT keyword which is not valid in VALUES clause.
4fill in blank
hard

Fill both blanks to reset the auto-increment counter to 1 for the table.

MySQL
ALTER TABLE users [1] = [2];
Drag options to blanks, or click blank then click option'
AAUTO_INCREMENT
B1
CRESET
DSTART
Attempts:
3 left
💡 Hint
Common Mistakes
Using RESET or START keywords which are not valid in this context.
Trying to set AUTO_INCREMENT without a value.
5fill in blank
hard

Fill all three blanks to create a table with an auto-increment column, insert a row, and select the auto-generated id.

MySQL
CREATE TABLE products (product_id INT [1] PRIMARY KEY, name VARCHAR(50));
INSERT INTO products (name) VALUES ([2]);
SELECT [3] FROM products WHERE name = 'Table';
Drag options to blanks, or click blank then click option'
AAUTO_INCREMENT
B'Table'
Cproduct_id
DNOT NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting AUTO_INCREMENT in the table definition.
Inserting the id manually instead of letting it auto-increment.
Selecting the wrong column in the SELECT statement.