0
0
MySQLquery~10 mins

NOT NULL and DEFAULT constraints 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 column that cannot have NULL values.

MySQL
CREATE TABLE users (id INT, name VARCHAR(100) [1]);
Drag options to blanks, or click blank then click option'
APRIMARY KEY
BNOT NULL
CAUTO_INCREMENT
DDEFAULT 'anonymous'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEFAULT instead of NOT NULL
Forgetting to add any constraint
2fill in blank
medium

Complete the code to set a default value for the column 'status'.

MySQL
CREATE TABLE orders (order_id INT, status VARCHAR(20) [1]);
Drag options to blanks, or click blank then click option'
ANOT NULL
BPRIMARY KEY
CDEFAULT 'pending'
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOT NULL instead of DEFAULT
Forgetting to quote string default values
3fill in blank
hard

Fix the error in the column definition to correctly set NOT NULL and DEFAULT constraints.

MySQL
CREATE TABLE products (id INT, price DECIMAL(5,2) [1] DEFAULT 0.00);
Drag options to blanks, or click blank then click option'
ANULL
BAUTO_INCREMENT
CPRIMARY KEY
DNOT NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of NOT NULL
Omitting NOT NULL when DEFAULT is present
4fill in blank
hard

Fill both blanks to create a column 'age' that cannot be NULL and has a default value of 18.

MySQL
CREATE TABLE members (id INT, age INT [1] [2] 18);
Drag options to blanks, or click blank then click option'
ANOT NULL
BDEFAULT
CAUTO_INCREMENT
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of NOT NULL and DEFAULT
Using AUTO_INCREMENT instead of DEFAULT
5fill in blank
hard

Fill all three blanks to create a table with a 'username' column that is NOT NULL, UNIQUE, and has a default value 'guest'.

MySQL
CREATE TABLE accounts (id INT PRIMARY KEY, username VARCHAR(50) [1] [2] [3] 'guest');
Drag options to blanks, or click blank then click option'
ANOT NULL
BDEFAULT
CUNIQUE
DAUTO_INCREMENT
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up UNIQUE and NOT NULL
Placing DEFAULT before NOT NULL
Using AUTO_INCREMENT incorrectly