{"id":1904,"date":"2019-05-01T11:26:26","date_gmt":"2019-05-01T04:26:26","guid":{"rendered":"http:\/\/www.sqlservertutorial.net\/?page_id=1904"},"modified":"2020-04-11T20:12:14","modified_gmt":"2020-04-11T13:12:14","slug":"sql-server-raiserror","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/","title":{"rendered":"SQL Server RAISERROR"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL Server <code>RAISERROR<\/code> statement to generate user-defined error messages.<\/p>\n\n\n\n<p class=\"note\">If you develop a new application, you should use the <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-throw\/\">THROW<\/a><\/code> statement instead.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-raiseerror-statement-overview'>SQL Server RAISEERROR statement overview <a href=\"#sql-server-raiseerror-statement-overview\" class=\"anchor\" id=\"sql-server-raiseerror-statement-overview\" title=\"Anchor for SQL Server &lt;code&gt;RAISEERROR&lt;\/code&gt; statement overview\">#<\/a><\/h2>\n\n\n\n<p>The <code>RAISERROR<\/code> statement allows you to generate your own error messages and return these messages back to the application using the same format as a system error or warning message generated by SQL Server Database Engine. In addition, the <code>RAISERROR<\/code> statement allows you to set a specific message id, level of severity, and state for the error messages.<\/p>\n\n\n\n<p>The following illustrates the syntax of the <code>RAISERROR<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">RAISERROR ( { message_id | message_text | @local_variable }  \n    { ,severity ,state }  \n    &#91; ,argument &#91; ,...n ] ] )  \n    &#91; <span class=\"hljs-keyword\">WITH<\/span> <span class=\"hljs-keyword\">option<\/span> &#91; ,...n ] ];\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Let&#8217;s examine the syntax of the <code>RAISERROR<\/code> for better understanding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='message_id'>message_id <a href=\"#message_id\" class=\"anchor\" id=\"message_id\" title=\"Anchor for message_id\">#<\/a><\/h3>\n\n\n\n<p>The <code>message_id<\/code> is a user-defined error message number stored in the <code>sys.messages<\/code> catalog view.<\/p>\n\n\n\n<p>To add a new user-defined error message number, you use the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/\">stored procedure<\/a> <code>sp_addmessage<\/code>. A user-defined error message number should be greater than 50,000. By default, the <code>RAISERROR<\/code> statement uses the <code>message_id<\/code> 50,000 for raising an error.<\/p>\n\n\n\n<p>The following statement adds a custom error message to the <code>sys.messages<\/code> view:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">EXEC sp_addmessage \n    @msgnum = 50005, \n    @severity = 1, \n    @msgtext = 'A custom error message';\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To verify the insert, you use the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>    \n    *\n<span class=\"hljs-keyword\">FROM<\/span>    \n    sys.messages\n<span class=\"hljs-keyword\">WHERE<\/span> \n    message_id = <span class=\"hljs-number\">50005<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To use this message_id, you execute the <code>RAISEERROR<\/code> statement as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">RAISERROR ( 50005,1,1)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here is the output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">A custom error message\nMsg 50005, Level 1, State 1\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To remove a message from the <code>sys.messages<\/code>, you use the stored procedure <code>sp_dropmessage<\/code>. For example, the following statement deletes the message id 50005:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">EXEC sp_dropmessage \n    @msgnum = 50005;  \n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='message_text'>message_text <a href=\"#message_text\" class=\"anchor\" id=\"message_text\" title=\"Anchor for message_text\">#<\/a><\/h3>\n\n\n\n<p>The <code>message_text<\/code> is a user-defined message with formatting like the <code>printf<\/code> function in C standard library. The <code>message_text<\/code> can be up to 2,047 characters, 3 last characters are reserved for ellipsis (&#8230;). If the <code>message_text<\/code> contains 2048 or more, it will be truncated and is padded with an ellipsis.<\/p>\n\n\n\n<p>When you specify the <code>message_text<\/code>, the <code>RAISERROR<\/code> statement uses message_id 50000 to raise the error message.<\/p>\n\n\n\n<p>The following example uses the <code>RAISERROR<\/code> statement to raise an error with a message text:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">RAISERROR ( 'Whoops, an error occurred.',1,1)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The output will look like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">Whoops, an error occurred.\nMsg 50000, Level 1, State 1\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='severity'>severity <a href=\"#severity\" class=\"anchor\" id=\"severity\" title=\"Anchor for severity\">#<\/a><\/h3>\n\n\n\n<p>The severity level is an integer between 0 and 25, with each level representing the seriousness of the error.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">0\u201310 Informational messages\n11\u201318 Errors\n19\u201325 Fatal errors\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='state'>state <a href=\"#state\" class=\"anchor\" id=\"state\" title=\"Anchor for state\">#<\/a><\/h3>\n\n\n\n<p>The state is an integer from 0 through 255. If you raise the same user-defined error at multiple locations, you can use a unique state number for each location to make it easier to find which section of the code is causing the errors. For most implementations, you can use 1.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='with-option'>WITH option <a href=\"#with-option\" class=\"anchor\" id=\"with-option\" title=\"Anchor for WITH option\">#<\/a><\/h3>\n\n\n\n<p>The option can be <code>LOG<\/code>, <code>NOWAIT<\/code>, or <code>SETERROR<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>WITH LOG<\/code> logs the error in the error log and application log for the instance of the SQL Server Database Engine.<\/li><li><code>WITH NOWAIT<\/code> sends the error message to the client immediately.<\/li><li><code>WITH SETERROR<\/code> sets the <code>ERROR_NUMBER<\/code> and <code>@@ERROR<\/code> values to message_id or 50000, regardless of the severity level.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-raiserror-examples'>SQL Server RAISERROR examples <a href=\"#sql-server-raiserror-examples\" class=\"anchor\" id=\"sql-server-raiserror-examples\" title=\"Anchor for SQL Server &lt;code&gt;RAISERROR&lt;\/code&gt; examples\">#<\/a><\/h2>\n\n\n\n<p>Let&#8217;s take some examples of using the <code>RAISERROR<\/code> statement to get a better understanding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='a-using-sql-server-raiserror-with-try-catch-block-example'>A) Using SQL Server RAISERROR with TRY CATCH block example <a href=\"#a-using-sql-server-raiserror-with-try-catch-block-example\" class=\"anchor\" id=\"a-using-sql-server-raiserror-with-try-catch-block-example\" title=\"Anchor for A) Using SQL Server &lt;code&gt;RAISERROR&lt;\/code&gt; with &lt;code&gt;TRY CATCH&lt;\/code&gt; block example\">#<\/a><\/h3>\n\n\n\n<p>In this example, we use the <code>RAISERROR<\/code> inside a <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-try-catch\/\">TRY<\/a><\/code> block to cause execution to jump to the associated <code>CATCH<\/code> block. Inside the <code>CATCH<\/code> block, we use the <code>RAISERROR<\/code> to return the error information that invoked the <code>CATCH<\/code> block.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DECLARE<\/span> \n    @ErrorMessage  <span class=\"hljs-keyword\">NVARCHAR<\/span>(<span class=\"hljs-number\">4000<\/span>), \n    @ErrorSeverity <span class=\"hljs-built_in\">INT<\/span>, \n    @ErrorState    <span class=\"hljs-built_in\">INT<\/span>;\n\n<span class=\"hljs-keyword\">BEGIN<\/span> TRY\n    RAISERROR(<span class=\"hljs-string\">'Error occurred in the TRY block.'<\/span>, <span class=\"hljs-number\">17<\/span>, <span class=\"hljs-number\">1<\/span>);\n<span class=\"hljs-keyword\">END<\/span> TRY\n<span class=\"hljs-keyword\">BEGIN<\/span> CATCH\n    <span class=\"hljs-keyword\">SELECT<\/span> \n        @ErrorMessage = ERROR_MESSAGE(), \n        @ErrorSeverity = ERROR_SEVERITY(), \n        @ErrorState = ERROR_STATE();\n\n    <span class=\"hljs-comment\">-- return the error inside the CATCH block<\/span>\n    RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState);\n<span class=\"hljs-keyword\">END<\/span> CATCH;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here is the output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">Msg 50000, Level 17, State 1, Line 16\nError occurred in the TRY block.\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='b-using-sql-server-raiserror-statement-with-a-dynamic-message-text-example'>B) Using SQL Server RAISERROR statement with a dynamic message text example <a href=\"#b-using-sql-server-raiserror-statement-with-a-dynamic-message-text-example\" class=\"anchor\" id=\"b-using-sql-server-raiserror-statement-with-a-dynamic-message-text-example\" title=\"Anchor for B) Using SQL Server &lt;code&gt;RAISERROR&lt;\/code&gt; statement with a dynamic message text example\">#<\/a><\/h3>\n\n\n\n<p>The following example shows how to use a local variable to provide the message text for a <code>RAISERROR<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DECLARE<\/span> @MessageText <span class=\"hljs-keyword\">NVARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>);\n<span class=\"hljs-keyword\">SET<\/span> @MessageText = N<span class=\"hljs-string\">'Cannot delete the sales order %s'<\/span>;\n\nRAISERROR(\n    @MessageText, <span class=\"hljs-comment\">-- Message text<\/span>\n    16, <span class=\"hljs-comment\">-- severity<\/span>\n    1, <span class=\"hljs-comment\">-- state<\/span>\n    N'2001' <span class=\"hljs-comment\">-- first argument to the message text<\/span>\n);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The output is as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">Msg 50000, Level 16, State 1, Line 5\nCannot <span class=\"hljs-keyword\">delete<\/span> the sales <span class=\"hljs-keyword\">order<\/span> <span class=\"hljs-number\">2001<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='when-to-use-raiserror-statement'>When to use RAISERROR statement <a href=\"#when-to-use-raiserror-statement\" class=\"anchor\" id=\"when-to-use-raiserror-statement\" title=\"Anchor for When to use &lt;code&gt;RAISERROR&lt;\/code&gt; statement\">#<\/a><\/h2>\n\n\n\n<p>You use the <code>RAISERROR<\/code> statement in the following scenarios:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Troubleshoot Transact-SQL code.<\/li><li>Return messages that contain variable text.<\/li><li>Examine the values of data.<\/li><li>Cause the execution to jump from a <code>TRY<\/code> block to the associated <code>CATCH<\/code> block.<\/li><li>Return error information from the <code>CATCH<\/code> block to the callers, either calling batch or application.<\/li><\/ul>\n\n\n\n<p>In this tutorial, you will learn how to use the SQL Server <code>RAISERROR<\/code> statement to generate user-defined error messages.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1904\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/\"\n\t\t\t\tdata-post-title=\"SQL Server RAISERROR\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1904\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/\"\n\t\t\t\tdata-post-title=\"SQL Server RAISERROR\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to use the SQL Server RAISERROR statement to generate user-defined error messages.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":777,"menu_order":11,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1904","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>An Essential Guide to SQL Server RAISERROR Statement<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the SQL Server RAISERROR statement to generate user-defined error messages.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An Essential Guide to SQL Server RAISERROR Statement\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the SQL Server RAISERROR statement to generate user-defined error messages.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-11T13:12:14+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-stored-procedures\\\/sql-server-raiserror\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-stored-procedures\\\/sql-server-raiserror\\\/\",\"name\":\"An Essential Guide to SQL Server RAISERROR Statement\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"datePublished\":\"2019-05-01T04:26:26+00:00\",\"dateModified\":\"2020-04-11T13:12:14+00:00\",\"description\":\"In this tutorial, you will learn how to use the SQL Server RAISERROR statement to generate user-defined error messages.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-stored-procedures\\\/sql-server-raiserror\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-stored-procedures\\\/sql-server-raiserror\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-stored-procedures\\\/sql-server-raiserror\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Stored Procedures\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-stored-procedures\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server RAISERROR\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An Essential Guide to SQL Server RAISERROR Statement","description":"In this tutorial, you will learn how to use the SQL Server RAISERROR statement to generate user-defined error messages.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/","og_locale":"en_US","og_type":"article","og_title":"An Essential Guide to SQL Server RAISERROR Statement","og_description":"In this tutorial, you will learn how to use the SQL Server RAISERROR statement to generate user-defined error messages.","og_url":"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2020-04-11T13:12:14+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/","url":"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/","name":"An Essential Guide to SQL Server RAISERROR Statement","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"datePublished":"2019-05-01T04:26:26+00:00","dateModified":"2020-04-11T13:12:14+00:00","description":"In this tutorial, you will learn how to use the SQL Server RAISERROR statement to generate user-defined error messages.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/sql-server-raiserror\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQL Server Stored Procedures","item":"https:\/\/www.sqlservertutorial.net\/sql-server-stored-procedures\/"},{"@type":"ListItem","position":3,"name":"SQL Server RAISERROR"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=1904"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1904\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/777"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=1904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}