Connecting Tech Pros Worldwide Forums | Help | Site Map

How much can it hold?

Mr aldo's Avatar
Newbie
 
Join Date: Jul 2007
Posts: 15
#1: Apr 18 '09
I know in MySQL with the INT type, you can also specify a length, such as INT(4), but I am currently having a problem.

How do you figure out the biggest number INT(4) can hold? Its probably an easy question, but I can't seem to find the answer.

Thanks!

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,758
#2: Apr 18 '09

re: How much can it hold?


Hi.

Check out 10.2. Numeric Types in the manual. You can see the range list for all integer types there.

In short, a normal Integer is 4 bytes, so it's ranges are:
  • -2,147,483,648 to 2,147,483,647 (Signed)
  • 0 to 4,294,967,295 (Unsigned)

The number you specify when you create the field (for example, INT(4)) defines the display width of the field, not the amount of data it can hold.

It is meant as a guideline to applications that should left-pad the number when displayed.
If you create the number with the optional ZEROFILL attribute, MySQL will do this automatically for you.

For example, a column defined as: Int(5) ZEROFILL, containing the number 1, would output: 00001

But even if the number you insert is larger than the display width, MySQL will not truncate it.
(Given that it is not larger than the maximum for the type)
Reply