How to raise an error within MySQL?


MySQL has introduced signals similar to an exception in other languages. Let us first see the syntax of signal.

SIGNAL SQLSTATE ' PredefinedValueforSignalError' 
SET MESSAGE_TEXT = 'AnyMessageInformation';

Above, we have set our own error message text as well.

We will apply the above query to get an error message with the help of signals.

mysql > SIGNAL SQLSTATE '42927' SET MESSAGE_TEXT = 'Error Generated';

The following is the output of the above query.

ERROR 1644 (42927): Error Generated

In the above output, ‘42927’ is a SQLSTATE and ‘Error Generated’ is an error message, which we added.

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements