Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference in int(11) and int(11) UNSIGNED?

Tags:

mysql

What's the difference in int(11) and int(11) UNSIGNED ?

like image 265
Webnet Avatar asked Mar 08 '11 20:03

Webnet


People also ask

What is the difference between int and unsigned int?

The XDR standard defines signed integers as integer. A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0 to 4294967295].

Is int the same as unsigned?

An int is signed by default, meaning it can represent both positive and negative values. An unsigned is an integer that can never be negative.

What is the difference between unsigned and unsigned int?

There is no difference. unsigned and unsigned int are both synonyms for the same type (the unsigned version of the int type).

Why would you use an unsigned int?

Unsigned integers are used when we know that the value that we are storing will always be non-negative (zero or positive).


2 Answers

An UNSIGNED type cannot be negative, but on the other hand it has twice as large a range for the positive integers. The types TINYINT, SMALLINT, MEDIUMINT, INT and BIGINT all have signed and unsigned versions.

For INT the ranges are defined as follows:

Type          Storage         Min           Max INT                 4 -2147483648    2147483647 INT UNSIGNED        4           0    4294967295 

The signed and unsigned types take the same storage space (4 bytes for INT).

See the documentation for more details.

like image 98
Mark Byers Avatar answered Sep 22 '22 08:09

Mark Byers


INT goes from -2147483648 to +2147483647
UNSIGNED INT goes from 0 to 4294967295

the 11 between the braces has no effect on the number, just how it's displayed.

like image 32
Matteo Riva Avatar answered Sep 25 '22 08:09

Matteo Riva