Working with Decimal and Floating-Point Types in MySQL
📖 Scenario: You are managing a small online store's database. You need to store product prices accurately, including cents, and also store product ratings which can have decimal values.
🎯 Goal: Create a MySQL table to store product information with prices using the DECIMAL type for exact values and ratings using the FLOAT type for approximate decimal values.
📋 What You'll Learn
Create a table named
products with columns for id, name, price, and rating.Use
DECIMAL(10,2) for the price column to store prices with two decimal places.Use
FLOAT for the rating column to store approximate decimal values.Set
id as the primary key and auto-increment it.Insert sample data with exact prices and decimal ratings.
💡 Why This Matters
🌍 Real World
Storing prices and ratings accurately is important for e-commerce and financial applications.
💼 Career
Understanding how to use decimal and floating-point types is essential for database developers and data analysts working with monetary and measurement data.
Progress0 / 4 steps