English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

How to trigger an error in MySQL?

MySQL introduces signals similar to exceptions in other languages. Let's first take a look at the syntax of the signal.

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

Above, we also set our own error message text.

We will use the above query to obtain the error message with the help of the signal.

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, we added it.