PDA

View Full Version : using an unsigned int over an int


crmpicco
05-04-2009, 01:40 PM
Hi,

Unless I am using auto_increment in the table, meaning I don't need negative values and it will give me twice as much positive numbers - what is the reason or advantage in using, for example "int(10) unsigned" over "int(10)" when specifying the data type of a column?

Thanks,
Picco

Fou-Lu
05-04-2009, 02:19 PM
There is no 'advantage' other than what you've specified.
An unsigned int value can contain 2^32-1 positive results, while a signed int can only contain 2^31-1 positive results.
Performance wise should carry no difference, just the number of auto_increment values you can have.
I assumed a modern system.

crmpicco
05-04-2009, 03:52 PM
Thanks for that, makes more sense to use an unsigned int then in my case.

Fou-Lu
05-04-2009, 06:25 PM
Thanks for that, makes more sense to use an unsigned int then in my case.

Definitely.
Only use a signed number if:

You need to make use of negative numbers OR
You're limiting what the user can have for numbers

b. doesn't make a lot of sense in SQL, that would be something that the language in use would worry about.