views:

72

answers:

3

In phpmyadmin there is a field length which you may specify, usually set to 11 on INT if nothing is specified.

  Field Name: ID
  Field Type: INT(11) // This is what I need to figure out!

How can I calculate the length, and what does the length actually stand for? Does it mean how many digits? Bytes?

And what is Unsigned and Signed got to do with this?

Thanks

+1  A: 

The field length is the pure character length, an int(11) can store eleven digits (f.e. 11,111,111,111).

Signed does mean, that the integer can have a negative value (range from f.e. -36768 to 36768), unsigned does mean that it does not have a sign, and can only store positive values (f.e. from 0 to 65536).

Bobby
Does the digit length include the +/- sign? The MySql INT range is 10 digits without the sign.
ron
I'm sorry but saying that "an int(11) can store eleven digits (f.e. 11,111,111,111)" is insane. Please read the MySQL manual page referred to in http://stackoverflow.com/questions/2206122/how-to-predict-calculate-field-length-of-numeric-values-int-in-mysql/2206181#2206181
Rowlf
+2  A: 

The type of the field (TINYINT, MEDIUMINT, INT, etc.) determines the maximum size of the integer you can put in such a field. Unsigned means you only want to store numbers greater than zero. Here is a reference table for numeric types in MySQL and what limits they have: MySQL Manual - Numeric Types.

If you define the field as unsigned, you get the same number of possible values, but they won't be split 50-50 between negative and positive numbers, as you will see from the table.

The number in brackets is the number that is used if you specify ZEROFILL on the field - that is useful if you need your numbers padded with zeros to a certain length. For example, if you create a new field as INT(5) ZEROFILL, it will display the numbers in it for you as

00001
00002
00003
etc.

but the range will still be from -2147483648 to 2147483648. The number in brackets will be ignored if you don't specify ZEROFILL when you define the field.

Rowlf