- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements