MySQL SHOW ERRORS Statement
Introduction
The SHOW ERRORS
statement in MySQL is used to display error messages generated by the most recent SQL statement execution. It provides details about syntax errors, constraint violations, and other execution failures.
Unlike SHOW WARNINGS
, which displays both warnings and errors, SHOW ERRORS
only displays errors.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjVPwPg6x3nlZ6d9LV_hDEI1fZ8New9SxyUMt6FJkoIUA5CJUiAwvrRJZinCMJWW23D0bOvnd-ZIF-E_YbnMM78eeDkORDn_GQzZ-6jr6JKNKNR9wmtAG0gkWFIixPG1j_tBzxhy-204Um/s16000/Mysql.jpg)
Syntax
Optional Clause:
To limit the number of errors displayed, use:
Where n
is the number of errors to display.
Example Usage
1. Generate an Error
Let's execute an incorrect SQL statement and use SHOW ERRORS
to inspect the error.
⚠ Error Output:
Now, use SHOW ERRORS
to display the last error:
Output:
- Level → The type of message (
Error
). - Code → The MySQL error code (
1064
for syntax error). - Message → The detailed error description.
2. Using LIMIT with SHOW ERRORS
To retrieve only the first error:
3. Checking the Number of Errors
To count the number of errors in the last statement:
Output:
Difference Between SHOW ERRORS and SHOW WARNINGS
Command | Shows Errors? | Shows Warnings? |
---|
SHOW ERRORS | ✅ Yes | ❌ No |
SHOW WARNINGS | ✅ Yes | ✅ Yes |
Conclusion
SHOW ERRORS
displays only errors from the last executed SQL statement.- It helps debug queries by showing MySQL error messages.
- Use
SHOW COUNT(*) ERRORS
to get the number of errors. - If you want both warnings and errors, use
SHOW WARNINGS
.
Would you like an example with stored procedures? 🚀