In the previous lesson, you learned about system errors, which are generated automatically by SQL Server.
In some cases, you will want to generate an error and return it back to a calling program. For example, stored procedures, which you will learn about later in this course, often require you to return an error back to the program that called the stored procedure.
These types of errors are called user-defined errors
. There are two types of user-defined errors:
- User-defined static error: A user-defined message that exists in the
sysmessages system catalog. These errors can be raised by your Transact-SQL statements. User-defined messages are added to the
sysmessages system catalog by using the
sp_addmessage system stored procedure.
- User-defined dynamic error: A user-defined message whose DESCRIPTION is generated dynamically and does not reside in the
sysmessages system catalog. This type of error can be raised by your Transact-SQL statement.