Mysql – When to use the different numeric data types – TINYINT / SMALLINT / MEDIUMINT / INT / BIGINT – MySQL

MySQLnumericsignedsqldatatypesunsigned

I read the answers given here: What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL? , so I now know how they store the data, but I'm still not sure how to set my database up. For example, if I want a field to be either 0 or 1 (sort of binary, 0 = off, 1 = on), do I use TINYINT with a length of 1?

My main question is, what does the LENGTH setting determine? As each NUMERIC data type already has their own associated data size.

Also, what is the difference between SIGNED and UNSIGNED, and why should I choose one over the other?

Best Answer

Diffrence between SIGNED and UNSIGNED is with UNSIGNED you can store only positive numbers.

For example : about INT (Normal INTEGER) values

The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295. If you are using PK auto_increment value then you should use UNSIGNED in this case.