0
0
MySQLquery~20 mins

CREATE TABLE syntax in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CREATE TABLE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the result of this CREATE TABLE statement?
Consider this MySQL statement:
CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(50), age INT);
What will be the structure of the employees table after running this?
MySQL
CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(50), age INT);
AA table named 'employees' with columns: id (integer, primary key), name (string up to 50 chars), age (integer)
BA table named 'employees' with columns: id (string), name (integer), age (integer)
CSyntax error due to missing semicolon
DA table named 'employees' with columns: id (integer), name (string), age (string)
Attempts:
2 left
💡 Hint
Look at the data types and constraints defined for each column.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this CREATE TABLE statement
Which option correctly identifies the syntax error in this statement?
CREATE TABLE products (product_id INT, product_name VARCHAR(100), price DECIMAL(10,2) NOT NULL,);
MySQL
CREATE TABLE products (product_id INT, product_name VARCHAR(100), price DECIMAL(10,2) NOT NULL,);
AMissing PRIMARY KEY declaration
BVARCHAR length must be 255 or less
CExtra comma before closing parenthesis causes syntax error
DDECIMAL data type is invalid
Attempts:
2 left
💡 Hint
Check punctuation carefully inside the parentheses.
🧠 Conceptual
advanced
2:00remaining
What does the following CREATE TABLE statement do?
Analyze this statement:
CREATE TABLE orders (order_id INT AUTO_INCREMENT PRIMARY KEY, order_date DATE DEFAULT CURRENT_DATE, customer_id INT, UNIQUE (customer_id, order_date));
What is the purpose of the UNIQUE constraint here?
MySQL
CREATE TABLE orders (order_id INT AUTO_INCREMENT PRIMARY KEY, order_date DATE DEFAULT CURRENT_DATE, customer_id INT, UNIQUE (customer_id, order_date));
AIt automatically increments customer_id
BIt makes customer_id the primary key
CIt allows duplicate customer_id values but unique order_date values
DIt ensures no two orders have the same customer_id and order_date combination
Attempts:
2 left
💡 Hint
Think about what UNIQUE means when applied to multiple columns.
🔧 Debug
advanced
2:00remaining
Why does this CREATE TABLE statement fail?
Given this statement:
CREATE TABLE inventory (item_id INT PRIMARY KEY, quantity INT DEFAULT 'ten');
Why will this cause an error?
MySQL
CREATE TABLE inventory (item_id INT PRIMARY KEY, quantity INT DEFAULT 'ten');
ADEFAULT value 'ten' is a string but quantity expects an integer
BPRIMARY KEY cannot be on item_id
CINT data type cannot have a DEFAULT value
DMissing comma between columns
Attempts:
2 left
💡 Hint
Check the data type compatibility of default values.
optimization
expert
2:00remaining
Which CREATE TABLE option optimizes storage for a large table with many NULL values?
You want to create a table with many optional columns that often have NULL values. Which option best optimizes storage in MySQL?
ADefine columns as NOT NULL with default values
BDefine columns as NULLABLE without default values
CUse VARCHAR columns with fixed length instead of TEXT
DUse ENUM type for all columns
Attempts:
2 left
💡 Hint
Think about how NULL values are stored in MySQL.