| title | sp_readerrorlog (Transact-SQL) | ||
|---|---|---|---|
| description | sp_readerrorlog allows you to read the contents of the SQL Server or SQL Server Agent error log file and filter on keywords. | ||
| author | rwestMSFT | ||
| ms.author | randolphwest | ||
| ms.reviewer | randolphwest | ||
| ms.date | 06/23/2025 | ||
| ms.service | sql | ||
| ms.subservice | system-objects | ||
| ms.topic | reference | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
[!INCLUDE SQL Server]
Allows you to read the contents of the SQL Server or SQL Server Agent error log file and filter on keywords.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sp_readerrorlog
[ [ @p1 = ] p1 ]
[ , [ @p2 = ] p2 ]
[ , [ @p3 = ] N'p3' ]
[ , [ @p4 = ] N'p4' ]
[ ; ]
The integer value of the log you want to view. @p1 is int, with a default of 0. The current error log has a value of 0. The previous is 1 (ERRORLOG.1), the one before previous is 2 (ERRORLOG.2), and so on.
The integer value for the product whose log you want to view. @p2 is int, with a default of NULL. Use 1 for SQL Server or 2 SQL Server Agent. If a value isn't specified, the SQL Server product is used.
The string value for a string you want to filter on when viewing the error log. @p3 is nvarchar(4000), with a default of NULL.
The string value for an extra string you want to filter on to further refine the search when viewing the error log. @p4 is nvarchar(4000), with a default of NULL. This parameter provides an extra filter to the first string search @p3.
None.
Displays the content of the requested error log. If filter strings are used, only the lines that match those strings are displayed.
Every time [!INCLUDE ssNoVersion] is started, the current error log is renamed to ERRORLOG.1; ERRORLOG.1 becomes ERRORLOG.2, ERRORLOG.2 becomes ERRORLOG.3, and so on. sp_readerrorlog enables you to read any of these error log files as long as the files exist.
[!INCLUDE sssql19-md] and earlier versions require VIEW SERVER STATE permission on the server.
[!INCLUDE sssql22-md] and later versions require VIEW ANY ERROR LOG permission on the server.
The following example cycles the [!INCLUDE ssNoVersion] error log.
EXECUTE sp_readerrorlog;EXECUTE sp_readerrorlog 1, 2;EXECUTE sp_readerrorlog 0, 1, 'database', 'start';