0

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?

user2507818
  • 2,719
  • 5
  • 21
  • 30

3 Answers3

2

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

Community
  • 1
  • 1
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
1

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.

xdazz
  • 158,678
  • 38
  • 247
  • 274
0

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.

Paul
  • 26,170
  • 12
  • 85
  • 119