Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Allows you to read the contents of the SQL Server or SQL Server Agent error log file and filter on keywords.
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 SQL Server 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.
SQL Server 2019 (15.x) and earlier versions require VIEW SERVER STATE permission on the server.
SQL Server 2022 (16.x) and later versions require VIEW ANY ERROR LOG permission on the server.
The following example cycles the SQL Server error log.
EXECUTE sp_readerrorlog;
EXECUTE sp_readerrorlog 1, 2;
EXECUTE sp_readerrorlog 0, 1, 'database', 'start';
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today