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)

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

89 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements