
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What does “unsigned” in MySQL mean and when to use it?
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.
Here is the example demo of unsigned type. Let us first create a table with “unsigned” column. The following is the query to create a table −
mysql> create table UnsignedDemoWithPositiveValue -> ( -> Distance int unsigned -> ); Query OK, 0 rows affected (0.86 sec)
If you will try to insert the upper value with unsigned 4294967295, then an error will generate since the value is out of range.
Inserting out of range value.
mysql> insert into UnsignedDemoWithPositiveValue values(4294967296); ERROR 1264 (22003): Out of range value for column 'Distance' at row 1
In the above example, I have inserted 4294967296, which is out of range, therefore error generates.
Now I am inserting another value 4294967295 into the table.
mysql> insert into UnsignedDemoWithPositiveValue values(4294967295); Query OK, 1 row affected (0.30 sec)
Above, you can see that the query executed successfully.
Now, let us see another example. If you insert negative records, then the following error can be seen −
mysql> insert into UnsignedDemoWithPositiveValue values(-124); ERROR 1264 (22003): Out of range value for column 'Distance' at row 1
I will now insert only positive value with value 124. The query is as follows −
mysql> insert into UnsignedDemoWithPositiveValue values(124); Query OK, 1 row affected (0.86 sec)
As you can see above, the query executed successfully.
Let us display the record with the help of select statement. The query is as follows −
mysql> select *from UnsignedDemoWithPositiveValue;
Here is the output −
+------------+ | Distance | +------------+ | 4294967295 | | 124 | +------------+ 2 rows in set (0.00 sec)
- Related Articles
- What does it mean by select 1 from MySQL table?
- What happens when a negative value is inserted to UNSIGNED column in MySQL?
- What Does It Mean to Close a Project?
- What is unsigned in MySQL?
- What does INT(7) in MySQL mean?
- "Makkal Needhi Maiam" what does it mean?
- What do you mean by PRIMARY KEY and how can we use it in MySQL table?
- What do you mean by FOREIGN KEY and how can we use it in MySQL table?
- What does it mean to run Infrastructure as Code?
- What does the KEY keyword mean in MySQL?
- What does parenthesis mean in MySQL SELECT (COLNAME)?
- What does it mean when a numeric constant in C/C++ is prefixed with a 0?
- When to use inline function and when not to use it in C/C++?
- What does the slash mean in a MySQL query?
- What Does It Mean to 'Throw Out Your Back'?
