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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
UNSIGNEDonly 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
INTEGERtype can store:Source: http://dev.mysql.com/doc/refman/5.6/en/integer-types.html
UNSIGNEDranges from0ton, while signed ranges from about-n/2ton/2.In this case, you have an
AUTO_INCREMENTID column, so you would not have negatives. Thus, useUNSIGNED. If you do not useUNSIGNEDfor theAUTO_INCREMENTcolumn, your maximum possible value will be half as high (and the negative half of the value range would go unused).