• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

integer-questions

http://dev.mysql.com/doc/mysql/en/Numeric_type_overview.html

In this overview you can see for example:
TINYINT = 0 - 255 (unsigned)
SMALLINT = 0 - 65535 (unsigned)
MEDIUMINT = 0 - 16777215 (unsigned)

Now in my database (MySQL) I use for example
SMALLINT(3) for numbers from 0 -> 999. But lately I saw I could use SMALLINT(1) as well for that...

Can someone clarify this?
0
G00fy
Asked:
G00fy
  • 2
  • 2
1 Solution
 
AlanJDMCommented:
"But lately I saw I could use SMALLINT(1) as well for that"

Where did you see that?


Alan

0
 
G00fyAuthor Commented:
In my database... I was using values of lets say '2300', normally I would use like SMALLINT(4) for that, but lately I saw that when I use SMALLINT(1) as well...
0
 
AlanJDMCommented:
I will be curious to see if anyone has any insight to this as well. I am not sure of the inner workings of MySQL but some logic and some basic math skills would tell you that 2300 can't be stored in one byte. My guess would be that the '1' doesn't represent what it appears to represent.



Alan
0
 
G00fyAuthor Commented:
My best guess is that the 1 means like (smallint = 2 bytes), so that it would mean 2bytes x 1
And then it is correct. If this is true however, then I am very stupid as all my indexes on my database are like INT(10) :-)
0
 
half_life_foolCommented:
http://dev.mysql.com/doc/mysql/en/Numeric_types.html


Another extension is supported by MySQL for optionally specifying the display width of an integer value in parentheses following the base keyword for the type (for example, INT(4)). This optional display width specification is used to left-pad the display of values having a width less than the width specified for the column.

The display width does not constrain the range of values that can be stored in the column, nor the number of digits that will be displayed for values having a width exceeding that specified for the column.


Meaning:
---------------
If you specify INT(4), then the storage size will be INT anyway. The 4 just means if you want to display it, it can be zero-padded to that length. (with other words: it doesn't matter that you specify 4 or 1 if you don't concern yourself with display, fe. if only using it in PHP).


Greetz
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now