Home » Mysql » The difference between signed and unsigned in MySQL?

The difference between signed and unsigned in MySQL?

Posted by: admin November 29, 2017 Leave a comment

Questions:

What is the difference between signed and unsigned in MySQL? And what does signed and unsigned mean?

Answers:

Unsigned numbers do not have the minus sign. Unsigned number can be only positive or zero (e.g. 123, 0). Signed numbers can be also negative (e.g. -42).

This answer explains the difference throughly.

Questions:
Answers:

The range that you can store in a given space. E.g., quoting from the docs:

 TINYINT[(M)] [UNSIGNED] [ZEROFILL]

A very small integer. The signed range
is -128 to 127. The unsigned range is
0 to 255.

and similarly of course for other larger integer types.

Questions:
Answers:

Range of possible values, as seen on this table.

It’s not specific to MySQL, it is a consequence of how integers are represented in a computer. Sign takes one bit for itself, thus the maximum number gets (roughly) halved. You can also think of it like shifting the whole thing by half the range downwards. (Also, because there’s an even number of available numbers and there aren’t two zeroes, you get one more negative number than positive). If you want to know more, read up on two’s complement.