MySQL provides exact integer and fixed-point types as well as approximate floating-point types. Select the type based on range, exactness and storage requirements.
| Type | Bytes | Signed range | Unsigned range |
|---|---|---|---|
| TINYINT | 1 | -128 to 127 | 0 to 255 |
| SMALLINT | 2 | -32,768 to 32,767 | 0 to 65,535 |
| MEDIUMINT | 3 | -8,388,608 to 8,388,607 | 0 to 16,777,215 |
| INT | 4 | -2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 |
| BIGINT | 8 | -2^63 to 2^63-1 | 0 to 2^64-1 |
DECIMAL(M,D) stores exact fixed-point values. M is total precision and D is the scale.
price DECIMAL(10,2)This is a common choice for currency-like values.
FLOAT and DOUBLE are approximate floating-point types. Use them for scientific measurements where approximation is acceptable, not for values that require exact decimal arithmetic.
INT(3). A display width does not restrict an integer to three digits and should not be used as a range rule.Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.