0
0
MySQLquery~10 mins

Variables and control flow 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 declare a variable named 'counter' with initial value 0.

MySQL
DECLARE counter [1];
Drag options to blanks, or click blank then click option'
AINT DEFAULT 0
BVARCHAR(10)
CDATE
DTEXT
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR for a number variable.
Not setting an initial value.
2fill in blank
medium

Complete the code to set the variable 'counter' to 5.

MySQL
SET [1] = 5;
Drag options to blanks, or click blank then click option'
A@counter
Bcounter
C$counter
D#counter
Attempts:
3 left
💡 Hint
Common Mistakes
Using @ prefix which is for user-defined session variables.
Using $ or # which are not valid prefixes.
3fill in blank
hard

Fix the error in the IF statement to check if 'counter' is less than 10.

MySQL
IF counter [1] 10 THEN
  SET counter = counter + 1;
END IF;
Drag options to blanks, or click blank then click option'
A!=
B=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using == which is invalid in MySQL.
Using = which is assignment, not comparison.
4fill in blank
hard

Fill both blanks to create a WHILE loop that runs while 'counter' is less than 5.

MySQL
WHILE counter [1] 5 DO
  SET counter = counter [2] 1;
END WHILE;
Drag options to blanks, or click blank then click option'
A<
B+
C-
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > which reverses the loop condition.
Using - which decreases counter causing infinite loop.
5fill in blank
hard

Fill all three blanks to declare a variable 'total', set it to 0, and increment it by 'value' inside a loop.

MySQL
DECLARE [1] INT DEFAULT 0;
SET [2] = 0;
SET total = total [3] value;
Drag options to blanks, or click blank then click option'
Atotal
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in declaration and assignment.
Using - which subtracts instead of adds.