sp_altermessage (Transact-SQL)sp_altermessage (Transact-SQL)

適用於: 是SQL Server 否Azure SQL Database 否Azure SQL 資料倉儲 否平行處理資料倉儲 APPLIES TO: yesSQL Server noAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

變更使用者定義狀態或在 SQL Server Database EngineSQL Server Database Engine 執行個體中之系統訊息。Alters the state of user-defined or system messages in an instance of the SQL Server Database EngineSQL Server Database Engine. 可以使用來檢視使用者自訂訊息sys.messages目錄檢視。User-defined messages can be viewed using the sys.messages catalog view.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax

  
sp_altermessage [ @message_id = ] message_number   ,[ @parameter = ]'write_to_log'  
   ,[ @parameter_value = ]'value'   

引數Arguments

[ @message_id = ] message_number[@message_id = ] message_number
要從訊息錯誤號碼sys.messagesIs the error number of the message to alter from sys.messages. message_numberint ,沒有預設值。message_number is int with no default value.

[ @parameter = ] 'write\_to\_log_' 可搭配 @parameter_value** 表示訊息會寫入至MicrosoftMicrosoftWindows 應用程式記錄檔。[ @parameter = ] 'write\_to\_log_' Is used with @parameter_value** to indicate that the message is to be written to the MicrosoftMicrosoft Windows application log. write_to_log已sysname ,沒有預設值。write_to_log is sysname with no default value. write_to_log必須設為 WITH_LOG 或 NULL。write_to_log must be set to WITH_LOG or NULL. 如果write_to_log設為 WITH_LOG 或 NULL,且值 @parameter_value** 是true**,訊息會寫入 Windows 應用程式記錄檔。If write_to_log is set to WITH_LOG or NULL, and the value for @parameter_value** is true, the message is written to the Windows application log. 如果write_to_log設為 WITH_LOG 或 NULL,且值 @parameter_value** 是false,訊息不一定會寫入 Windows 應用程式記錄檔,但可能寫入錯誤的產生方式而定。If write_to_log is set to WITH_LOG or NULL and the value for **@parameter_value** is false, the message is not always written to the Windows application log, but may be written depending upon how the error was raised. 如果write_to_log指定的值 **@parameter_value** 也必須指定。If write_to_log is specified, the value for **@parameter_value** must also be specified.

注意

如果訊息寫入 Windows 應用程式記錄檔中,它也會寫入 Database EngineDatabase Engine 錯誤記錄檔中。If a message is written to the Windows application log, it is also written to the Database EngineDatabase Engine error log file.

[ @parameter_value = ]'value_' 可搭配 @parameter** 表示錯誤會寫入至MicrosoftMicrosoftWindows 應用程式記錄檔。[ @parameter_value = ]'value_' Is used with @parameter** to indicate that the error is to be written to the MicrosoftMicrosoft Windows application log. 已varchar(5) ,沒有預設值。value is varchar(5), with no default value. 如果 ,則為 true,錯誤一律會寫入 Windows 應用程式記錄檔。If true, the error is always written to the Windows application log. 如果false,錯誤不一定會寫入 Windows 應用程式記錄檔,但也可能會寫入錯誤的產生方式而定。If false, the error is not always written to the Windows application log, but may be written depending upon how the error was raised. 如果指定,則write_to_log for **@parameter** 也必須指定。If value is specified, write_to_log for **@parameter** must also be specified.

傳回碼值Return Code Values

0 (成功) 或 1 (失敗)0 (success) or 1 (failure)

結果集Result Sets

NoneNone

備註Remarks

效果sp_altermessage了 with_log 選項是類似於 RAISERROR WITH LOG 參數,不同之處在於sp_altermessage變更現有訊息的記錄行為。The effect of sp_altermessage with the WITH_LOG option is similar to that of the RAISERROR WITH LOG parameter, except that sp_altermessage changes the logging behavior of an existing message. 如果訊息已改成 WITH_LOG,它便一律會寫入 Windows 應用程式記錄檔中,不論使用者如何叫用錯誤都是如此。If a message has been altered to be WITH_LOG, it is always written to the Windows application log, regardless of how a user invokes the error. 即使執行 RAISERROR 時未設定 WITH_LOG 選項,仍會將錯誤寫入 Windows 應用程式記錄檔中。Even if RAISERROR is executed without the WITH_LOG option, the error is written to the Windows application log.

系統訊息可以藉由修改sp_altermessageSystem messages can be modified by using sp_altermessage.

PermissionsPermissions

需要的成員資格serveradmin固定的伺服器角色。Requires membership in the serveradmin fixed server role.

範例Examples

下列範例會使現有的訊息 55001 記錄到 Windows 應用程式記錄檔中。The following example causes existing message 55001 to be logged to the Windows application log.

EXECUTE sp_altermessage 55001, 'WITH_LOG', 'true';  
GO  

另請參閱See Also

RAISERROR (Transact-SQL) RAISERROR (Transact-SQL)
sp_addmessage (Transact-SQL) sp_addmessage (Transact-SQL)
sp_dropmessage (Transact-SQL) sp_dropmessage (Transact-SQL)
系統預存程序 (Transact-SQL)System Stored Procedures (Transact-SQL)