Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
01-13-2013, 02:54 PM #1
- Join Date
- Feb 2012
- Thanked 0 Times in 0 Posts
The diference between tinyint(4) and tinyint(3)?
1. What is tinyint(4)?
2. Is 4 the number of digits?
3. Could you tell me the diference between tinyint(4) and tinyint(3)?
4. Is it possible to have tinyint(7) ?
Thank u very much!
01-13-2013, 04:27 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,668 Times in 2,637 Posts
The 4 in the tinyint should represent the zerofill of the number. You can have a tinyint(50) if you want. All that changes is the left padding of 0's that appear before the number stored. So tinyint(4) with a value of 56 would be 0056. It won't alter the range you are allowed. I believe that the zerofill only works with unsigned numbers, so with a tinyint you can still only have 0 - 255 as a valid range.
Last edited by Fou-Lu; 01-13-2013 at 04:33 PM.
01-13-2013, 08:03 PM #3
And zerofill is, in my opinion, a bad idea.
It gives the mistaken impression that MySQL is actually storing numbers with leading zeroes.
Nothing could be further from the truth!
INTERNALLY, there is NO DIFFERENCE between TINYINT(0) and TINYINT(50).
The *ONLY* difference is that, when you SELECT a field declared as TINYINT(50) ZEROFILL, MySQL must convert the *NUMBER* in the field to a *STRING*! Because ONLY strings can actually have zero fill.
On top of all that, when you USE a ZEROFILL field in a server-side language, such as PHP or ASP or JSP, you many be surprised at what the actual value is.
At least in ASP, for example, the zero fill is *REMOVED* from the number and the number is treated as a DOUBLE (a.k.a. REAL) number, not as an integer, at all.
So the best thing you can do, in my opinion, is *NEVER* use ZEROFILL.Be yourself. No one else is as qualified.