Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between signed and unsigned in MySQL?

Tags:

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

like image 940
Write Avatar asked Jul 01 '10 04:07

Write


People also ask

What is the difference between unsigned and signed?

The term "unsigned" in computer programming indicates a variable that can hold only positive numbers. The term "signed" in computer code indicates that a variable can hold negative and positive values.

What does unsigned mean in MySQL?

The “unsigned” in MySQL is a data type. Whenever we write an unsigned to any column that means you cannot insert negative numbers. Suppose, for a very large number you can use unsigned type. The maximum range with unsigned int is 4294967295. Note: If you insert negative value you will get a MySQL error.

Is MySQL int signed or unsigned?

Except for standard INT and SMALLINT data types, MySQL supports TINYINT, MEDIUMINT, and BIGINT numeric data types that can be SIGNED and UNSIGNED.

What is the signed and unsigned range of DB?

The unsigned range is 0 to 16777215 . A normal-size integer. The signed range is -2147483648 to 2147483647 .


2 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.

like image 192
Juha Syrjälä Avatar answered Oct 09 '22 08:10

Juha Syrjälä


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.

like image 20
Alex Martelli Avatar answered Oct 09 '22 10:10

Alex Martelli