int(10) va int(11)

int(10) va int(11)

am 14.06.2010 18:14:12 von Ryan Chan

Assume MySQL int range (unsigned) is from 0 to 4294967295

There are total 10 digits.

Why a lot of tutorial in the web tell you to declare,

e.g.

CREATE TABLE t1 (f INT(11) UNSIGNED);

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: int(10) va int(11)

am 14.06.2010 20:04:27 von Michael Dykman

11 characters of display allow for any int of any size, signed or
unsigned. When you do not specify a length attribute in a
declaration, MySQL uses 11 as the default.

For your application, use what makes sense for your problem's domain.

- michael dykman


On Mon, Jun 14, 2010 at 12:14 PM, Ryan Chan wrote:
> Assume MySQL int range (unsigned) is from 0 to 4294967295
>
> There are total 10 digits.
>
> Why a lot of tutorial in the web tell you to declare,
>
> e.g.
>
> =A0CREATE TABLE t1 =A0(f INT(11) UNSIGNED);
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: =A0 =A0http://lists.mysql.com/mysql?unsub=3Dmdykman@gmail=
..com
>
>



--=20
- michael dykman
- mdykman@gmail.com

May the Source be with you.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg

RE: int(10) va int(11)

am 14.06.2010 20:29:25 von Daevid Vincent

AFAIK, the number in parenthesis is ONLY for display purposes in formatting
the size of the column in mySQL command line output, NOT the size of the
data that can be held.

I think they use (11) because unsigned will need one extra character for
the minus sign.

INT SIGNED = -2147483648 to 2147483647

Now this changes for things like a CHAR(2) where that *IS the column is
only going to handle 2 characters. Or VARCHAR(10) where that column will
handle from 0 to 10 characters. Same goes for FLOAT(7,4) which means 7
total digits and 4 of them are decimal places.

But for *INT columns, I don't think the same is true. It's cosmetic only.
Someone PLEASE correct me if I'm wrong. It's kind of silly if you ask me.
This one special case just adds confusion.

http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

Another extension is supported by MySQL for optionally specifying the
display width of integer data types in parentheses following the base
keyword for the type (for example, INT(4)). This optional display width may
be used by applications to display integer values having a width less than
the width specified for the column by left-padding them with spaces. (That
is, this width is present in the metadata returned with result sets.
Whether it is used or not is up to the application.)

The display width does not constrain the range of values that can be stored
in the column, nor the number of digits that are displayed for values
having a width exceeding that specified for the column. For example, a
column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to
32767, and values outside the range allowed by three characters are
displayed using more than three characters.

> -----Original Message-----
> From: Ryan Chan [mailto:ryanchan404@gmail.com]
> Sent: Monday, June 14, 2010 9:14 AM
> To: MySql
> Subject: int(10) va int(11)
>
> Assume MySQL int range (unsigned) is from 0 to 4294967295
>
> There are total 10 digits.
>
> Why a lot of tutorial in the web tell you to declare,
>
> e.g.
>
> CREATE TABLE t1 (f INT(11) UNSIGNED);
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=daevid@daevid.com
>


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: int(10) va int(11)

am 16.06.2010 10:44:38 von Lucio Chiappetti

On Mon, 14 Jun 2010, Michael Dykman wrote:

> 11 characters of display allow for any int of any size, signed or
> unsigned. When you do not specify a length attribute in a
> declaration, MySQL uses 11 as the default.

As an astrophysicist, I've always considered a flaw the fact that mysql
(or SQL in general ?) mix up things like the number of bytes taken by a
quantity, and the number of digits recommended for display.

In our parliance (e.g. the FITS data format used by the International
Astronomical Union for data exchange) this is mixing up TTYPE (e.g. 8- 16-
or 32- bit integers, 32- or 64-bit floats) and TDISP (the Fortran-like
format suggested for display).

In mysql I always use the generic type (int or float or double, rarely
things like bigint or tinyint) for numeric quantities, without any
number-of-digit indication.

For floats they are not just used for display, but sometime affect also
comparison and that's very annoying if you work usually with numbers like
1.43E-12 !

--
------------------------------------------------------------ ------------
Lucio Chiappetti - INAF/IASF - via Bassini 15 - I-20133 Milano (Italy)
------------------------------------------------------------ ------------
Citizens entrusted of public functions have the duty to accomplish them
with discipline and honour
[Art. 54 Constitution of the Italian Republic]
------------------------------------------------------------ ------------
For more info : http://www.iasf-milano.inaf.it/~lucio/personal.html
------------------------------------------------------------ ------------

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org