
- 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 happens when a negative value is inserted to UNSIGNED column in MySQL?
Error occurs when you set a negative value to UNSIGNED column in MySQL. For example, let us first create a table with an UNSIGNED field −
mysql> create table UnsignedDemo -> ( -> Id int UNSIGNED -> ); Query OK, 0 rows affected (0.79 sec)
The error is as follows whenever you insert negative value to column Id which is declared as UNSIGNED −
mysql> INSERT INTO UnsignedDemo VALUES(-100); ERROR 1264 (22003): Out of range value for column 'Id' at row 1
Example
However, positive values work well for UNSIGNED. The same is shown in the example below. Insert some records in the above table using insert command. The query is as follows −
mysql> INSERT INTO UnsignedDemo VALUES(100); Query OK, 1 row affected (0.15 sec) mysql> INSERT INTO UnsignedDemo VALUES(1000); Query OK, 1 row affected (0.15 sec) mysql> INSERT INTO UnsignedDemo VALUES(0); Query OK, 1 row affected (0.11 sec) mysql> INSERT INTO UnsignedDemo VALUES(100000000); Query OK, 1 row affected (0.27 sec)
Display all records from the table using a select statement. The query is as follows −
mysql> SELECT *FROM UnsignedDemo;
Output
+-----------+ | Id | +-----------+ | 100 | | 1000 | | 0 | | 100000000 | +-----------+ 4 rows in set (0.00 sec)
- Related Articles
- What happens when I insert the value ‘NULL’ in an AUTO_INCREMENT MySQL column?
- Display the warning message when a FLOAT value is inserted into DECIMAL in MySQL?
- What is unsigned in MySQL?
- What happens when buffer is set to a value "none" in JSP?
- What is the Maximum Value of smallint(6) unsigned in MySQL?
- What does “unsigned” in MySQL mean and when to use it?
- What happens when we multiply a negative integer with a positive integer?
- Exclude rows based on column value when another duplicate column value is found in MySQL?
- What happens when you add a double value to a String in java?
- What happens when we try to add a number to undefined value?
- What happens when iron is heated?
- What happens when sugar is heated?
- How to select row when column must satisfy multiple value in MySQL?
- What happens when you insert nothing after declaring a column “timestamp default CURRENT_TIMESTAMP”?
- What happens when nitric acid is added to eggshell?

Advertisements