📖 Scenario: You are managing a small online store database. You need to create a table to store product information including product ID, stock quantity, and total sales count. Different integer types are used to save space depending on the size of the numbers.
🎯 Goal: Create a MySQL table called products with columns using TINYINT, INT, and BIGINT integer types appropriately to store product ID, stock quantity, and total sales count.
📋 What You'll Learn
Create a table named products
Add a column product_id using TINYINT
Add a column stock_quantity using INT
Add a column total_sales using BIGINT
💡 Why This Matters
🌍 Real World
Using appropriate integer types helps save storage space and improves database performance in real-world applications like inventory management.
💼 Career
Database developers and administrators must choose correct data types to optimize storage and ensure data integrity.
Progress0 / 4 steps
1
Create the products table with product_id column
Write a SQL statement to create a table called products with one column named product_id of type TINYINT.
MySQL
Hint
Use CREATE TABLE products (product_id TINYINT); to create the table with the product_id column.
2
Add stock_quantity column with INT type
Add a new column named stock_quantity of type INT to the products table using an ALTER TABLE statement.
MySQL
Hint
Use ALTER TABLE products ADD COLUMN stock_quantity INT; to add the new column.
3
Add total_sales column with BIGINT type
Add a new column named total_sales of type BIGINT to the products table using an ALTER TABLE statement.
MySQL
Hint
Use ALTER TABLE products ADD COLUMN total_sales BIGINT; to add the new column.
4
Complete the products table with all integer columns
Combine all previous steps into a single SQL script that creates the products table with product_id as TINYINT, stock_quantity as INT, and total_sales as BIGINT.
MySQL
Hint
Define all columns inside one CREATE TABLE statement separated by commas.
Practice
(1/5)
1. Which MySQL integer type should you use to store a small number between 0 and 255 efficiently?
easy
A. BIGINT
B. INT
C. TINYINT
D. SMALLINT
Solution
Step 1: Understand the range of TINYINT and compare with other types
TINYINT can store values from 0 to 255 when unsigned, which fits small numbers efficiently. INT and BIGINT store much larger numbers but use more space. SMALLINT also uses more space unnecessarily.
Final Answer:
TINYINT -> Option C
Quick Check:
Small numbers (0-255) = TINYINT [OK]
Hint: Use TINYINT for numbers up to 255 to save space [OK]
Common Mistakes:
Choosing INT for small numbers wastes space
Confusing TINYINT with SMALLINT
Not considering unsigned range
2. Which of the following is the correct syntax to declare a NOT NULL BIGINT column named user_id in MySQL?
easy
A. user_id BIGINT;
B. BIGINT user_id;
C. user_id INT BIG;
D. user_id BIGINT NOT NULL;
Solution
Step 1: Check correct order of declaration
In MySQL, the column name comes first, then the data type, optionally followed by constraints like NOT NULL. Only A follows this: user_id BIGINT NOT NULL;.
Final Answer:
user_id BIGINT NOT NULL; -> Option D
Quick Check:
Column name + type + constraints = correct syntax [OK]
Hint: Column name first, then type, then constraints [OK]
Common Mistakes:
Putting type before column name
Using invalid order of keywords
Missing semicolon in some contexts
3. Given the table orders with a column order_count TINYINT UNSIGNED, what will be the result of this query?
INSERT INTO orders (order_count) VALUES (300); SELECT order_count FROM orders;
medium
A. 300
B. Error: Out of range value
C. 0
D. 44
Solution
Step 1: Understand TINYINT UNSIGNED range and insert effect
TINYINT UNSIGNED stores 0-255 only. 300 exceeds range, so INSERT throws 'Error: Out of range value' (default strict mode).
Final Answer:
Error: Out of range value -> Option B
Quick Check:
Value > 255 in TINYINT UNSIGNED causes error [OK]
Hint: Check value fits type range before insert [OK]
Common Mistakes:
Assuming values wrap around silently
Ignoring unsigned range limits
Expecting automatic truncation without error
4. You have a column defined as INT but you want to store numbers larger than 4,294,967,295. Which change fixes the problem?
medium
A. Change the column type to BIGINT
B. Change the column type to TINYINT
C. Add UNSIGNED to the INT column
D. Use VARCHAR instead of INT
Solution
Step 1: Understand INT range limits and select proper type
Signed INT max ~2.1 billion, UNSIGNED INT max 4,294,967,295. BIGINT handles much larger (up to ~9 quintillion).
Final Answer:
Change the column type to BIGINT -> Option A
Quick Check:
BIGINT stores bigger numbers than INT [OK]
Hint: Use BIGINT for numbers bigger than INT max [OK]
Common Mistakes:
Using TINYINT which is smaller
Adding UNSIGNED but still too small
Switching to VARCHAR loses numeric benefits
5. You want to store user scores that can be very large, but you also want to save space when scores are small. Which MySQL integer type strategy is best?
hard
A. Use INT for most scores and BIGINT only if scores exceed INT range
B. Use TINYINT and switch to BIGINT if needed later
C. Always use BIGINT for all scores
D. Use BIGINT but compress data manually
Solution
Step 1: Balance storage and range needs
TINYINT too small; always BIGINT wastes space. Use INT initially (efficient for small/medium), ALTER to BIGINT later if needed.
Final Answer:
Use INT for most scores and BIGINT only if scores exceed INT range -> Option A
Quick Check:
Balance size and range with INT then BIGINT [OK]
Hint: Start with INT, upgrade to BIGINT if needed [OK]
Common Mistakes:
Always using BIGINT wastes space
Starting with TINYINT causes overflow
Manual compression is complex and error-prone
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.