Reputation: 3037
I created two fields text(varchar)
, number(int)
using mysql. But I am not sure what size i should put for varchar()
, int()
, for varchar()
, I checked here: http://dev.mysql.com/doc/refman/5.0/en/char.html, and know if I put varchar(4)
, it means: can hold up to 4 characters. But for int(4)
, I checked here: http://dev.mysql.com/doc/refman/5.0/en/integer-types.html, It is said: Maximum Value:(Signed/Unsigned)(2147483647/4294967295)
Question:
for int(4)
, how did it get this value2147483647/4294967295
? if i put int(8)
, what would the value be?
Upvotes: 0
Views: 190
Reputation: 27364
See the MySQL Numeric Type Documentation. These things are well-documented.
The range for a signed
INT
is [-2147483648, 2147483647].Note that in the case of
INT(x)
, x is the "display width" and has nothing to do with the range or space requirements:MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits ... display width does not constrain [or expand] the range of values that can be stored in the column.
Mysql int(11) number out of range
Upvotes: 2
Reputation: 27423
Well, from the browser console I note:
Math.pow(2, 4*8)
is 4294967296
and half that is 2147483648
those are 1 off the maximum (unsigned/signed) integer that can be stored in binary form using 4 8-bit bytes.
Upvotes: 0
Reputation: 160833
int(4)
an INT with a display width of four digits.
int(8)
an INT with a display width of eight digits.
Minimum Value/Maximum Value
are the same for an int
type which use 4 bytes to storage.
-2147483648
to 2147483647
for signed, and 0
to 4294967296
for unsigned.
Upvotes: 1