Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Choosing the correct numeric data type is one of the most critical decisions in database engineering. An incorrect choice can lead to subtle financial calculation bugs (such as 0.1 + 0.2 equaling 0.30000000000000004) or waste hundreds of gigabytes of server RAM and SSD storage across billions of rows.
MySQL provides five distinct integer types depending on the range of numbers you need to store:
| Type | Storage Bytes | Signed Range | Unsigned Range | Common Use Case |
|---|---|---|---|---|
TINYINT | 1 byte | -128 to 127 | 0 to 255 | Age, status codes, flags. |
SMALLINT | 2 bytes | -32,768 to 32,767 | 0 to 65,535 | Year, country codes, items in cart. |
MEDIUMINT | 3 bytes | -8,388,608 to 8,388,607 | 0 to 16,777,215 | Zip codes, customer IDs for medium apps. |
INT / INTEGER | 4 bytes | -2.14 billion to +2.14 billion | 0 to 4.29 billion | Standard primary keys, order IDs. |
BIGINT | 8 bytes | -9.22 quintillion to +9.22 quintillion | 0 to 18.44 quintillion | Global payment transactions, analytics logs. |
UNSIGNED KeywordIf a column will never store negative values (e.g., student age, product price, quantity in stock), designate it as UNSIGNED. This doubles the positive range without consuming any additional disk space!
DECIMAL(M, D) (Exact Numeric)DECIMAL(10, 2) can store up to 8 digits before the dot and 2 digits after: -99999999.99 to +99999999.99.DECIMAL for prices, salaries, currency, and taxes!FLOAT & DOUBLE (Approximate Numeric)FLOAT (4 bytes): ~7 decimal digits of precision.DOUBLE (8 bytes): ~15 decimal digits of precision.0.1 cannot be represented with absolute exactness in binary, leading to rounding discrepancies. Use strictly for scientific measurements, GPS coordinates, or game coordinates where speed outweighs microscopic rounding precision.FLOAT or DOUBLE will result in reconciliation errors during financial audits.INT(11) in MySQL: The number inside parentheses in INT(11) or INT(4) is only a display width hint used with ZEROFILL. It does not limit the maximum value or storage size! An INT(4) can still store 2,000,000,000. In MySQL 8.0.19+, integer display widths are officially deprecated.BIGINT for a column that will never exceed 100 entries wastes 7 bytes per row. Across 100 million rows, that is 700 MB of wasted RAM!INT column occupy in MySQL?UNSIGNED keyword accomplish on an integer column?DECIMAL(8, 2), what is the maximum number of digits allowed before the decimal point?INT(5) historically indicate in MySQL versions prior to 8.0.19?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Database Metadata & Server Status | String & Text Types |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.