[SOLVED] When should I use UNSIGNED and SIGNED INT in MySQL?

Issue

When should I use UNSIGNED and SIGNED INT in MySQL ?
What is better to use or this is just personal prefernce ?
Because I’ve seen it used like this;

id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

Solution

UNSIGNED only stores positive numbers (or zero). On the other hand, signed can store negative numbers (i.e., may have a negative sign).

Here’s a table of the ranges of values each INTEGER type can store:

MySQL INTEGER types and lengths
Source: http://dev.mysql.com/doc/refman/5.6/en/integer-types.html

UNSIGNED ranges from 0 to n, while signed ranges from about -n/2 to n/2.

In this case, you have an AUTO_INCREMENT ID column, so you would not have negatives. Thus, use UNSIGNED. If you do not use UNSIGNED for the AUTO_INCREMENT column, your maximum possible value will be half as high (and the negative half of the value range would go unused).

Answered By – Wiseguy

Answer Checked By – Marie Seifert (BugsFixing Admin)

Leave a Reply

Your email address will not be published.