
- 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
Display the warning message when a FLOAT value is inserted into DECIMAL in MySQL?
You can create a temporary table with data type DECIMAL to get a warning when a float value is inserted into an int column. Display the same warning using SHOW WARNINGS.
Let us create a table to understand. The query is as follows to create a table.
mysql> create temporary table WarningDemo -> ( -> Value DECIMAL -> ); Query OK, 0 rows affected (0.13 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into WarningDemo values(9.80); Query OK, 1 row affected, 1 warning (0.03 sec)
Here we are getting a warning. Let us check the warning using SHOW command. The syntax is as follows −
SHOW WARNINGS;
The query is as follows −
mysql> show warnings;
Output
+-------+------+--------------------------------------------+ | Level | Code | Message | +-------+------+--------------------------------------------+ | Note | 1265 | Data truncated for column 'Value' at row 1 | +-------+------+--------------------------------------------+ 1 row in set (0.00 sec)
Display all records from the table using a select statement. The query is as follows −
mysql> select *from WarningDemo;
Output
+-------+ | Value | +-------+ | 10 | +-------+ 1 row in set (0.00 sec)
- Related Articles
- What happens when a negative value is inserted to UNSIGNED column in MySQL?
- Change value of decimal(19, 2) when inserting into the database in MySQL?
- How to display a float with two decimal places in Python?
- How to display a message when a given number is in the range using JavaScript?
- Display 3 decimal places in MySQL?
- Display substring in MySQL if the string is less than a specific length or display a custom message if it is more?
- Check if table exists in MySQL and display the warning if it exists?
- Split float value in two columns of a MySQL table?
- Perform MySQL SELECT on dates inserted into the table as VARCHAR values
- What is the difference between a float, double and a decimal in C#?
- Display message when hovering over something with mouse cursor in Tkinter Python
- How do we display inserted text in HTML?
- Ignore MySQL INSERT IGNORE statement and display an error if duplicate values are inserted in a table
- How to round MySQL column with float values and display the result in a new column?
- How to deal with warning message `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. in R while creating a histogram?

Advertisements