SHOW WARNINGS

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.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

SHOW WARNINGS [LIMIT [offset,] count]

SHOW COUNT(*) WARNINGS

Explanation

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.

Examples

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.