Challenge - 5 Problems
Data Type Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this SQL query with different data types?
Consider a table products with columns:
id INT, name VARCHAR(10), price DECIMAL(5,2), and release_date DATE. The table has one row: (1, 'Gadget', 99.99, '2023-01-15'). What will this query return?SELECT id, name, price, release_date FROM products;
SQL
SELECT id, name, price, release_date FROM products;
Attempts:
2 left
💡 Hint
Remember that DECIMAL(5,2) stores two digits after the decimal point exactly, and DATE format is YYYY-MM-DD.
✗ Incorrect
The DECIMAL(5,2) type stores numbers with two decimal places exactly, so 99.99 is stored as is. The DATE type stores dates in 'YYYY-MM-DD' format. VARCHAR(10) stores the string as given. So the output matches option B exactly.
🧠 Conceptual
intermediate1:30remaining
Which data type is best for storing a person's birth date?
You want to store a person's birth date in a database column. Which data type should you choose to store this information correctly and efficiently?
Attempts:
2 left
💡 Hint
Think about what kind of data a birth date is and how databases store dates.
✗ Incorrect
The DATE data type is designed to store calendar dates efficiently and allows date functions to be used. VARCHAR stores text, INT stores numbers without date context, and DECIMAL is for precise numbers, not dates.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this table creation statement
Which option contains a syntax error in the SQL statement below?
CREATE TABLE orders ( order_id INT, customer_name VARCHAR(50), order_total DECIMAL(7,2), order_date DATE );
SQL
CREATE TABLE orders ( order_id INT, customer_name VARCHAR(50), order_total DECIMAL(7,2), order_date DATE );
Attempts:
2 left
💡 Hint
Check for trailing commas in the column list.
✗ Incorrect
Option A has a trailing comma after the last column definition, which causes a syntax error in SQL. The other options are syntactically correct.
❓ optimization
advanced1:30remaining
Choose the most storage-efficient data type for storing product prices up to 9999.99
You need to store product prices that can be up to 9999.99 dollars. Which data type is the most storage-efficient and appropriate for this use case?
Attempts:
2 left
💡 Hint
Consider the maximum value and decimal places needed.
✗ Incorrect
DECIMAL(7,2) can store numbers up to 99999.99, which covers 9999.99 easily. DECIMAL(5,2) only stores up to 999.99, which is too small. INT cannot store decimals. VARCHAR wastes space and is not numeric.
🔧 Debug
expert2:30remaining
Why does this INSERT statement fail for a DECIMAL column?
Given a table
sales with a column amount DECIMAL(4,2), why does this statement fail?INSERT INTO sales (amount) VALUES (123.456);
SQL
INSERT INTO sales (amount) VALUES (123.456);
Attempts:
2 left
💡 Hint
DECIMAL(4,2) means total 4 digits with 2 after decimal point.
✗ Incorrect
DECIMAL(4,2) means total 4 digits, 2 after decimal. So max value is 99.99. The integer part 123 is too large to fit. The decimal places (3) is more than 2, but the main error is integer part size.