0
0
MySQLquery~10 mins

Column definitions and 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 define a column named 'age' as an integer.

MySQL
CREATE TABLE Persons (age [1]);
Drag options to blanks, or click blank then click option'
AINT
BTEXT
CVARCHAR(100)
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR for numeric data.
Using DATE for age.
2fill in blank
medium

Complete the code to add a NOT NULL constraint to the 'name' column.

MySQL
CREATE TABLE Employees (name VARCHAR(50) [1]);
Drag options to blanks, or click blank then click option'
ANOT NULL
BDEFAULT NULL
CUNIQUE
DPRIMARY KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEFAULT NULL instead of NOT NULL.
Confusing UNIQUE with NOT NULL.
3fill in blank
hard

Fix the error in the code to set 'id' as the primary key.

MySQL
CREATE TABLE Orders (id INT [1], order_date DATE);
Drag options to blanks, or click blank then click option'
AUNIQUE
BPRIMARY KEY
CNOT NULL
DFOREIGN KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE instead of PRIMARY KEY.
Forgetting to add NOT NULL with PRIMARY KEY.
4fill in blank
hard

Fill all three blanks to define a 'salary' column as decimal with 10 digits total and 2 decimal places, and ensure it cannot be NULL.

MySQL
CREATE TABLE Staff (salary [1]([2], 2) [3]);
Drag options to blanks, or click blank then click option'
ADECIMAL
B10
CNOT NULL
DVARCHAR
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR for salary.
Omitting NOT NULL constraint.
5fill in blank
hard

Fill all three blanks to define a 'username' column as VARCHAR(30), make it UNIQUE, and set a default value 'guest'.

MySQL
CREATE TABLE Users (username [1]([2]) DEFAULT 'guest' [3]);
Drag options to blanks, or click blank then click option'
AVARCHAR
B30
CUNIQUE
DINT
Attempts:
3 left
💡 Hint
Common Mistakes
Using INT for username.
Forgetting UNIQUE constraint.