0
0
SQLquery~20 mins

Column data types (INT, VARCHAR, DATE, DECIMAL) in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Data Type Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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;
A1 | Gadget | 99.99 | 2023/01/15
B1 | Gadget | 99.99 | 2023-01-15
C1 | Gadget | 100 | 2023-01-15
D1 | Gadget | 99.9900 | 15-01-2023
Attempts:
2 left
💡 Hint
Remember that DECIMAL(5,2) stores two digits after the decimal point exactly, and DATE format is YYYY-MM-DD.
🧠 Conceptual
intermediate
1: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?
ADATE
BVARCHAR(10)
CINT
DDECIMAL(8,0)
Attempts:
2 left
💡 Hint
Think about what kind of data a birth date is and how databases store dates.
📝 Syntax
advanced
2: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
);
ACREATE TABLE orders (order_id INT, customer_name VARCHAR(50), order_total DECIMAL(7,2), order_date DATE,);
BCREATE TABLE orders (order_id INT, customer_name VARCHAR(50), order_total DECIMAL(7,2), order_date DATETIME);
CCREATE TABLE orders (order_id INT, customer_name VARCHAR(50), order_total DECIMAL(7,2), order_date DATE);
DCREATE TABLE orders (order_id INT, customer_name VARCHAR(50), order_total DECIMAL(7,2), order_date DATE NOT NULL);
Attempts:
2 left
💡 Hint
Check for trailing commas in the column list.
optimization
advanced
1: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?
AVARCHAR(10)
BINT
CDECIMAL(7,2)
DDECIMAL(5,2)
Attempts:
2 left
💡 Hint
Consider the maximum value and decimal places needed.
🔧 Debug
expert
2: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);
AThe syntax of the INSERT statement is incorrect.
BThe value 123.456 has more decimal places than allowed by DECIMAL(4,2).
CDECIMAL(4,2) does not allow decimal values, only integers.
DThe integer part 123 is too large for DECIMAL(4,2).
Attempts:
2 left
💡 Hint
DECIMAL(4,2) means total 4 digits with 2 after decimal point.