檢視 SQL Server 錯誤記錄Viewing the SQL Server Error Log

本主題適用於: 是SQL Server (僅限 Windows)否Azure SQL Database否Azure SQL 資料倉儲否平行處理資料倉儲 THIS TOPIC APPLIES TO: yesSQL Server (Windows only)noAzure SQL DatabasenoAzure SQL Data WarehousenoParallel Data Warehouse

您可以檢視 SQL ServerSQL Server 錯誤記錄檔,確定處理序已順利完成 (例如,備份與還原作業、批次命令或其他指令碼和處理序)。View the SQL ServerSQL Server error log to ensure that processes have completed successfully (for example, backup and restore operations, batch commands, or other scripts and processes). 這有助於偵測任何目前的或潛在的問題區域,包括自動復原訊息 (尤其是 SQL ServerSQL Server 的執行個體已停止又重新啟動時)、核心訊息或其他伺服器層級的錯誤訊息。This can be helpful to detect any current or potential problem areas, including automatic recovery messages (particularly if an instance of SQL ServerSQL Server has been stopped and restarted), kernel messages, or other server-level error messages.

您可以使用 SQL ServerSQL Server 或任何文字編輯器來檢視 Transact-SQLSQL Server Management Studio 錯誤記錄檔。View the SQL ServerSQL Server error log by using Transact-SQLSQL Server Management Studio or any text editor. 如需有關如何檢視錯誤記錄檔的詳細資訊,請參閱< Open Log File Viewer>。For more information about how to view the error log, see Open Log File Viewer. 根據預設,錯誤記錄檔是位於 Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOGERRORLOG.n 檔案中。By default, the error log is located at Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG and ERRORLOG.n files.

每次啟動 SQL ServerSQL Server 執行個體時,就會建立新的錯誤記錄檔,不過, sp_cycle_errorlog 系統預存程序可用來循環錯誤記錄檔,而不必重新啟動 SQL ServerSQL Server執行個體。A new error log is created each time an instance of SQL ServerSQL Server is started, although the sp_cycle_errorlog system stored procedure can be used to cycle the error log files without having to restart the instance of SQL ServerSQL Server. 通常, SQL ServerSQL Server 會保留前 6 個記錄檔的備份,並提供副檔名 .1 給最新的記錄檔備份,提供副檔名 .2 給第二新的備份...依此類推。Typically, SQL ServerSQL Server retains backups of the previous six logs and gives the most recent log backup the extension .1, the second most recent the extension .2, and so on. 目前的錯誤記錄檔並沒有副檔名。The current error log has no extension.

請注意,您也可以在離線或無法啟動的 SQL ServerSQL Server 執行個體上檢視 SQL ServerSQL Server 錯誤記錄檔。Be aware that you can also view the SQL ServerSQL Server error log on instances of SQL ServerSQL Server that are offline or cannot start. 如需詳細資訊,請參閱 檢視離線記錄檔For more information, see View Offline Log Files.