Database Engine 錯誤嚴重性Database Engine Error Severities

適用於: 是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產生錯誤時,錯誤的嚴重性會指出 SQL ServerSQL Server所發生的問題類型。When an error is raised by the SQL Server Database EngineSQL Server Database Engine, the severity of the error indicates the type of problem encountered by SQL ServerSQL Server.

嚴重性層級Levels of Severity

下表列出和描述 SQL Server Database EngineSQL Server Database Engine所產生之錯誤的嚴重性層級。The following table lists and describes the severity levels of the errors raised by the SQL Server Database EngineSQL Server Database Engine.

嚴重性層級Severity level DescriptionDescription
0-90-9 傳回狀態資訊或報告不嚴重之錯誤的參考訊息。Informational messages that return status information or report errors that are not severe. Database EngineDatabase Engine 不會產生嚴重性 0-9 的系統錯誤。The Database EngineDatabase Engine does not raise system errors with severities of 0 through 9.
1010 傳回狀態資訊或報告不嚴重之錯誤的參考訊息。Informational messages that return status information or report errors that are not severe. 基於相容性考量, Database EngineDatabase Engine 會先將嚴重性 10 轉換成嚴重性 0,再將錯誤資訊傳回給發出呼叫的應用程式。For compatibility reasons, the Database EngineDatabase Engine converts severity 10 to severity 0 before returning the error information to the calling application.
11-1611-16 指出使用者能夠更正的錯誤。Indicate errors that can be corrected by the user.
1111 指出給定的物件或實體不存在。Indicates that the given object or entity does not exist.
1212 因特殊查詢提示而不使用鎖定之查詢的特殊嚴重性。A special severity for queries that do not use locking because of special query hints. 在某些情況下,這些陳述式所執行的讀取作業可能會產生不一致的資料,因為並沒有採取鎖定來保證一致性。In some cases, read operations performed by these statements could result in inconsistent data, since locks are not taken to guarantee consistency.
1313 指出交易死結錯誤。Indicates transaction deadlock errors.
1414 指出與安全性相關的錯誤,例如,沒有權限。Indicates security-related errors, such as permission denied.
1515 指出 Transact-SQLTransact-SQL 命令的語法錯誤。Indicates syntax errors in the Transact-SQLTransact-SQL command.
1616 指出使用者能夠更正的一般錯誤。Indicates general errors that can be corrected by the user.
17-1917-19 指出使用者無法更正的軟體錯誤。Indicate software errors that cannot be corrected by the user. 請通知系統管理員這個問題。Inform your system administrator of the problem.
1717 指出陳述式使 SQL ServerSQL Server 將資源 (如記憶體、鎖定,或資料庫的磁碟空間) 用完,或超出系統管理員所設定的某項限制。Indicates that the statement caused SQL ServerSQL Server to run out of resources (such as memory, locks, or disk space for the database) or to exceed some limit set by the system administrator.
1818 指出 Database EngineDatabase Engine 軟體發生問題,但陳述式執行完成,且 Database EngineDatabase Engine 執行個體的連接也得到維護。Indicates a problem in the Database EngineDatabase Engine software, but the statement completes execution, and the connection to the instance of the Database EngineDatabase Engine is maintained. 每當出現嚴重性層級 18 的訊息時,都應該通知系統管理員。The system administrator should be informed every time a message with a severity level of 18 occurs.
1919 指出超出不可設定的 Database EngineDatabase Engine 限制,已終止目前的批次處理序。Indicates that a nonconfigurable Database EngineDatabase Engine limit has been exceeded and the current batch process has been terminated. 嚴重性層級 19 或以上的錯誤訊息,會停止執行目前的批次。Error messages with a severity level of 19 or higher stop the execution of the current batch. 嚴重性層級 19 的錯誤很少,必須由系統管理員或主要支援提供者來更正。Severity level 19 errors are rare and must be corrected by the system administrator or your primary support provider. 當出現嚴重性層級 19 的訊息時,請連絡您的系統管理員。Contact your system administrator when a message with a severity level 19 is raised. 嚴重性層級 19-25 的錯誤訊息會寫入錯誤記錄中。Error messages with a severity level from 19 through 25 are written to the error log.
20-2420-24 指出系統問題,這些都是嚴重錯誤,表示執行陳述式或批次的 Database EngineDatabase Engine 工作已不在執行中。Indicate system problems and are fatal errors, which means that the Database EngineDatabase Engine task that is executing a statement or batch is no longer running. 工作會將發生情況的相關資訊記錄下來,再終止作業。The task records information about what occurred and then terminates. 在大部份的情況下,通往 Database EngineDatabase Engine 執行個體的應用程式連接也會終止。In most cases, the application connection to the instance of the Database EngineDatabase Engine may also terminate. 如果發生這個情況,隨著問題而不同,應用程式可能會無法重新連接。If this happens, depending on the problem, the application might not be able to reconnect.

這個範圍的錯誤訊息可能會影響所有存取相同資料庫之資料的處理序,且可能表示資料庫或物件已經損毀。Error messages in this range can affect all of the processes accessing data in the same database and may indicate that a database or object is damaged. 嚴重性層級 19-24 的錯誤訊息會寫入錯誤記錄中。Error messages with a severity level from 19 through 24 are written to the error log.
2020 指出陳述式發生問題。Indicates that a statement has encountered a problem. 由於問題只影響到目前的工作,因此,資料庫本身可能並沒有損毀。Because the problem has affected only the current task, it is unlikely that the database itself has been damaged.
2121 指出發生影響目前資料庫中所有工作的問題,但資料庫本身可能並沒有損毀。Indicates that a problem has been encountered that affects all tasks in the current database, but it is unlikely that the database itself has been damaged.
2222 指出軟體或硬體問題已損毀訊息所指定的資料表或索引。Indicates that the table or index specified in the message has been damaged by a software or hardware problem.

嚴重性層級 22 的錯誤很少發生。Severity level 22 errors occur rarely. 如果發生,請執行 DBCC CHECKDB 來判斷資料庫中的其他物件是否也已損毀。If one occurs, run DBCC CHECKDB to determine whether other objects in the database are also damaged. 可能只有緩衝快取發生問題,磁碟本身並沒有問題。The problem might be in the buffer cache only and not on the disk itself. 若是如此,重新啟動 Database EngineDatabase Engine 執行個體便可以更正這個問題。If so, restarting the instance of the Database EngineDatabase Engine corrects the problem. 若要繼續作業,您必須重新連接 Database EngineDatabase Engine執行個體;否則,請利用 DBCC 來修復問題。To continue working, you must reconnect to the instance of the Database EngineDatabase Engine; otherwise, use DBCC to repair the problem. 在某些情況下,您可能需要還原資料庫。In some cases, you may have to restore the database.

如果重新啟動 Database EngineDatabase Engine 執行個體仍未更正這個問題,就表示磁碟發生問題。If restarting the instance of the Database EngineDatabase Engine does not correct the problem, then the problem is on the disk. 有時終結錯誤訊息所指定的物件可以解決這個問題。Sometimes destroying the object specified in the error message can solve the problem. 例如,如果訊息報告 Database EngineDatabase Engine 執行個體在非叢集索引中找到長度是 0 的資料列,請刪除這個索引,再重建它。For example, if the message reports that the instance of the Database EngineDatabase Engine has found a row with a length of 0 in a nonclustered index, delete the index and rebuild it.
2323 指出由於硬體或軟體發生問題,因此,整個資料庫的完整性有問題。Indicates that the integrity of the entire database is in question because of a hardware or software problem.

嚴重性層級 23 的錯誤很少發生。Severity level 23 errors occur rarely. 如果發生,請執行 DBCC CHECKDB 來判斷損毀的範圍。If one occurs, run DBCC CHECKDB to determine the extent of the damage. 可能只有快取發生問題,磁碟本身並沒有問題。The problem might be in the cache only and not on the disk itself. 若是如此,重新啟動 Database EngineDatabase Engine 執行個體便可以更正這個問題。If so, restarting the instance of the Database EngineDatabase Engine corrects the problem. 若要繼續作業,您必須重新連接 Database EngineDatabase Engine執行個體;否則,請利用 DBCC 來修復問題。To continue working, you must reconnect to the instance of the Database EngineDatabase Engine; otherwise, use DBCC to repair the problem. 在某些情況下,您可能需要還原資料庫。In some cases, you may have to restore the database.
2424 指出媒體失敗。Indicates a media failure. 系統管理員可能需要還原資料庫。The system administrator may have to restore the database. 您也可能需要電洽您的硬體廠商。You may also have to call your hardware vendor.

使用者自訂的錯誤訊息嚴重性User-Defined Error Message Severity

您可以利用sp_addmessage ,將嚴重性 1-25 的使用者自訂錯誤訊息加入 sys.messages 目錄檢視中。sp_addmessage can be used to add user-defined error messages with severities from 1 through 25 to the sys.messages catalog view. RAISERROR 可以使用這些使用者自訂的錯誤訊息。These user-defined error messages can be used by RAISERROR. 如需詳細資訊,請參閱 sp_addmessage (Transact-SQL)For more information, see sp_addmessage (Transact-SQL).

RAISERROR 可以用來產生使用者定義的錯誤訊息,其嚴重性為 1 到 25。RAISERROR can be used to generate user-defined error messages with severities from 1 through 25. RAISERROR 可以參考儲存在 sys.messages 目錄檢視的使用者定義錯誤訊息,或是動態建立訊息。RAISERROR can reference a user-defined error message stored in the sys.messages catalog view or build a message dynamically. 當在產生錯誤時使用 sys.messages 中的使用者自訂錯誤訊息,RAISERROR 指定的嚴重性會覆寫 sys.messages 所指定的嚴重性。When using the user-defined error message in sys.messages while generating an error, the severity specified by RAISERROR overrides the severity specified in sys.messages. 如需詳細資訊,請參閱 RAISERROR (Transact-SQL)For more information, see RAISERROR (Transact-SQL).

錯誤嚴重性和 TRY...CATCHError Severity and TRY...CATCH

TRY...CATCH 建構會捕捉嚴重性大於 10 而並未終止資料庫連接的所有執行錯誤。A TRY...CATCH construct catches all execution errors with severity greater than 10 that do not terminate the database connection.

嚴重性 0-10 的錯誤是資訊訊息,不會使執行動作跳出 TRY...CATCH 建構的 CATCH 區塊。Errors with severity from 0 through 10 are informational messages and do not cause execution to jump from the CATCH block of a TRY...CATCH construct.

CATCH 區塊不會處理嚴重性通常是 20-25 的終止資料庫連接的錯誤,因為在連接終止時,會中止執行動作。Errors that terminate the database connection, usually with severity from 20 through 25, are not handled by the CATCH block because execution is aborted when the connection terminates.

如需詳細資訊,請參閱 TRY...CATCH (Transact-SQL)所發生的問題類型。For more information, see TRY...CATCH (Transact-SQL).

擷取錯誤嚴重性Retrieving Error Severity

您可以利用 ERROR_SEVERITY 系統函式來擷取造成執行 TRY...CATCH 建構的 CATCH 區塊之錯誤的嚴重性。The ERROR_SEVERITY system function can be used to retrieve the severity of the error that caused the CATCH block of a TRY...CATCH construct to be run. 如果是在 CATCH 區塊範圍之外呼叫,ERROR_SEVERITY 會傳回 NULL。ERROR_SEVERITY returns NULL if called outside the scope of a CATCH block. 如需詳細資訊,請參閱 ERROR_SEVERITY (Transact-SQL)For more information, see ERROR_SEVERITY (Transact-SQL).

另請參閱See Also

了解 Database Engine 錯誤 Understanding Database Engine Errors
sys.messages (Transact-SQL) sys.messages (Transact-SQL)
系統函數 (Transact-SQL) System Functions (Transact-SQL)
TRY...CATCH (Transact-SQL)TRY...CATCH (Transact-SQL)