1

I have two tables with same column.

First table:

DESC orders;
Field           Type       Null Key      Default    Extra
order_id        int(8)     unsigned      zerofill   NO  PRI (null)auto_increment
customer_id     int(10)    unsigned      YES        MUL (null)  

Second table:

DESC items;
Field            Type      Null Key      Default    Extra
item_id          int(11)   unsigned      NO PRI (null)  auto_increment
order_id         int(10)   unsigned      NO PRI (null)  

Based on tables above order_id have different data precision.

But upon checking on information_schema database the precision is identical

SELECT c.TABLE_SCHEMA, c.TABLE_NAME, c.COLUMN_NAME, c.DATA_TYPE, c.NUMERIC_PRECISION, t.ENGINE from information_schema.COLUMNS c
INNER JOIN information_schema.TABLES t on t.TABLE_NAME = c.TABLE_NAME
WHERE c.TABLE_SCHEMA = 'database' AND c.COLUMN_NAME = 'order_id' and c.TABLE_NAME in ('orders','items');

The result was.

TABLE_SCHEMA    TABLE_NAME  COLUMN_NAME DATA_TYPE   NUMERIC_PRECISION   ENGINE
database         items      order_id    int         10                  MyISAM
database         orders     order_id    int         10                  MyISAM

Which of them is accurate? The one displayed in DESC table of the result from information schema? Thank you.

1 Answer 1

4

NUMBER_PRECISION is useless except for one case: ZEROFILL. Otherwise, it is an indication of how many columns of output are needed to display the largest number.

INT UNSIGNED needs 10 digits. INT SIGNED needs 11 columns -- a sign (if negative) and 10 digits.

Ignore the column there. Ignore it when you see int(11).

And don't bother declaring a column to be INT(100) or INT(2); it is still a 32-bit (4-byte) signed binary number.

7
  • Meaning, values in information_schema is not accurate? Commented Aug 29, 2017 at 2:05
  • 1
    No, meaning that it refers to display width, not "numeric precision". Note that it includes room for the sign, which is not normally considered part of precision. 31 or 32 would be a 'correct' precision for signed or unsigned int, since it is stored in binary.
    – Rick James
    Commented Aug 29, 2017 at 2:09
  • Do you think I am going to have a problem in future if I leave those order_ids' in different precision? Commented Aug 30, 2017 at 0:27
  • For INT, inconsistent values of number_precision will not matter. (For DECIMAL, it may.)
    – Rick James
    Commented Aug 30, 2017 at 0:58
  • Alright on last confirmation, any precision declared in creating the column like column_1 INT(1) and column_2 INT(100) should hold up to 2,147,483,647? Commented Aug 30, 2017 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.