What is the best Mysql type to store numeric values

Asked

Viewed 111 times

0

I have a table where you store the number of places in numerical values. I would like to know the best type mysql to store these values, taking into account that it can be calculated with another field that will receive the same type of another table.

  • It depends on the size of the numbers you want to store. The medium is INT. accepting a maximum of 2147483648 and a minimum of -2147483648.

  • Show ball bfavaretto. So would not have problems in calculating 02 fields that store numerical values right? For example (02 variables in PHP with values from BD).: $campo1 - $campo2.

  • No. But with the data you have in the other question, you can’t safely say that it’s a typing problem. PHP should convert correctly at the time of subtraction. There is something strange in your application set that we don’t know what it is.

1 answer

1

number of waves in numerical values

Whereas there will be no negative number, the field may be of the type int unsigned which will store from 0 to 4294967295.

If it is an immense db and is considering space reduction, you can use other integer numeric types:

CREATE TABLE `inttypes` (                       -- SIGNED ( -X ~ X )    UNSIGNED ( 0 ~ X )
    `tinyint` TINYINT(4) DEFAULT NULL,          -- 127                  255
    `smallint` SMALLINT(6) DEFAULT NULL,        -- 32767                65535
    `mediumint` MEDIUMINT(9) DEFAULT NULL,      -- 8388607              16777215
    `int` INT(11) DEFAULT NULL,                 -- 2147483647           4294967295
    `bigint` BIGINT(20) DEFAULT NULL            -- 9223372036854775807  18446744073709551615
);

Source: Mysql 8.0 Reference Manual - 11.2.1 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT

Browser other questions tagged

You are not signed in. Login or sign up in order to post.