← Back to MySQL Course | Chapter 3: Data Types | Lesson 1 of 8

Numeric Data Types

Integer Types

Integer types range from TINYINT (1 byte, up to 255 unsigned) to BIGINT (8 bytes, enormous range) — picking the smallest type that comfortably fits your data saves storage and speeds up indexes on large tables.

Example: Integer Types

sql
CREATE TABLE items (
  small_count TINYINT,
  big_count BIGINT
);

Decimal Types

DECIMAL stores numbers as exact fixed-point values rather than approximations, making it the correct choice for currency and other figures where even tiny rounding drift is unacceptable over many calculations.

Example: Decimal Types

sql
CREATE TABLE invoices (amount DECIMAL(10,2));
INSERT INTO invoices VALUES (19.99);

Float and Double

FLOAT and DOUBLE trade a small amount of precision for speed and compactness, which is fine for scientific measurements or graphing data but risky for anything requiring exact totals, like invoices.

Example: Float and Double

sql
CREATE TABLE measurements (temperature FLOAT, distance DOUBLE);

Unsigned Numbers

Marking a numeric column UNSIGNED removes the ability to store negative values but doubles the positive range available — a good fit for columns like age or quantity that are never negative anyway.

Example: Unsigned Numbers

sql
CREATE TABLE people (age INT UNSIGNED);

Zerofill Attribute

ZEROFILL pads a numeric column's displayed value with leading zeros up to its defined width (e.g. 007 instead of 7), and as a side effect it implicitly makes the column UNSIGNED as well.

Example: Zerofill Attribute

sql
CREATE TABLE codes (id INT ZEROFILL);
INSERT INTO codes VALUES (7);

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.