Use this MySQL statement to display warning messages, error messages, and notes for previous SQL statements for the current session. It also has a COUNT(*) clause that you can use to see the number of error messages generated rather than displaying them.
hits past month: 13 ; last updated: may 4, 2009 - 2:34am ; parent: Data Manipulation StatementsSHOW WARNINGS [LIMIT [offset,] count] SHOW COUNT(*) WARNINGS
Use this MySQL statement to display warning messages, error messages, and notes for previous SQL statements for the current session. This MySQL statement is available as of Version 4.1 of MySQL. To find out the number of such messages generated by the previous statement in the session, use the COUNT(*) clause. Use the LIMIT clause to limit the number of messages displayed. An offset can be given along with the limit to specify a starting point for displaying messages.
Here are a couple of examples of how you can use this MySQL statement:
INSERT INTO clients (client_name, telephone)
VALUES('Marie & Associates', '504-486-1234');
Query OK, 1 row affected, 1 warning (0.00 sec)
SHOW COUNT(*) WARNINGS;
+-------------------------+
| @@session.warning_count |
+-------------------------+
| 1 |
+-------------------------+
SHOW WARNINGS;
+---------+------+--------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------+
| Warning | 1265 | Data truncated for column 'client_name' at row 1 |
+---------+------+--------------------------------------------------+
In this example, we've entered the name of a client and their telephone number in the table clients, but in the results we see that one warning was issued. The second statement returns the number of messages; of course, the last line of the results from the INSERT already told us this. Notice that the results are stored in the session variable warning_count. The third SQL statement displays the warning message. These statement are perhaps more meaningful when used with an API program in which you would like to capture number of errors generated or the error messages for a specific purpose or analysis.