On Fri, 5 Mar 2004 16:45:12 -0500, Chris Ruprecht wrote:

>On Friday 05 March 2004 06:36, Kae Verens wrote:
>> Richard Davey wrote:
>> > Hi all,
>> >
>> > Sorry for such a newbie question! But I have been digging through the
>> > O'Reilly MySQL book + MySQL Cookbook and cannot find an answer to what
>> > I think is a very simple question:
>> >
>> > When creating an unsigned INT field, how does the value in brackets
>> > (if given) limit the size of the field? I.e. what is the difference in
>> > possible maximum values held between an INT(10) and an INT(4)? I know
>> > MySQL will create an INT(10) as standard but I'm not sure I need it to
>> > be able to hold a number that high.
>> IIRC, the highest permitted value of an unsigned int is:
>> 8^(number of bytes)-1
>> so, INT(4) above is 8^4-1 (approx 65500), and INT(10) is 8^10-1 (quite a
>> bit bigger)
>The X in Int(X) is the number of byes, each byte has 8 bits, hence, a 4 byte 
>integer has 32 bits, a 8 byte integer has 64 bits.
>actually, Int(4) is 2^(4 x 8 bit) - 1 = 4294967295
>Int(8) = 2^(64) - 1 = 18446744073709551615
>Usually, a distinction is made between signed and unsigned, most database 
>systems use signed integer, so the maximum int(4) value is 2^32 / 2 - 1 or 
>2^31 - 1 and the max signed int(8) value = 2^63 - 1.

The value in parentheses in INT(x) is unrelated to the possible values in the column 
which, in the MySQL integer number column type declarations, are defined by INT, 

Reading the mysql manual instead of engaging in unrestrained speculation, you would 
learn that:

"As an extension to the SQL-92 standard, MySQL also supports the integer types 
TINYINT, MEDIUMINT, and BIGINT as listed in the tables above. 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 width specification is used to left-pad the display of values whose width is 
less than the width specified for the column, but 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 whose width exceeds that specified for the column. ..."


Pay particular attention to the second and third sentences in the excerpt above.


>Best regards,
>> Kae

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to