如何在 SQL Server 2014 的存储过程中打印错误消息?

How to print Error Message in stored procedure in SQL Server 2014?

我正在使用 SQL Server 2014。谁能告诉我如何在我的存储过程中打印特定的错误消息?

您尝试过使用 Throw 吗? SQL 2014 不支持原生 SP 的 RAISERROR()。虽然支持投掷。

  THROW [ { error_number | @local_variable },
    { message | @local_variable },
    { state | @local_variable } ] [ ; ]

例如:

   THROW 5000, 'THROW TEST', 1

https://msdn.microsoft.com/en-us/library/ee677615.aspx

http://sqlhints.com/2013/06/30/differences-between-raiserror-and-throw-in-sql-server/