Errors and warnings from the SQL Server error log in the last 7 days (current and previous log): failed logins, I/O warnings, deadlocks, memory paged out and so on. Part of my SQL Server health check: run Health Check 00 for a one-page summary, then the numbered scripts for the detail behind each area. Read-only, changes nothing. Tested on SQL Server 2017 and 2025.
-- 08_Error_Log.sql - errors and warnings from the SQL Server error log in the last 7 days (current and previous log). Read-only.
SET NOCOUNT ON;
DECLARE @log TABLE (LogDate datetime, ProcessInfo nvarchar(100), [Text] nvarchar(max));
INSERT @log EXEC master.dbo.xp_readerrorlog 0, 1;
BEGIN TRY INSERT @log EXEC master.dbo.xp_readerrorlog 1, 1; END TRY BEGIN CATCH END CATCH;
SELECT LogDate, ProcessInfo, [Text]
FROM @log
WHERE LogDate > DATEADD(DAY, -7, GETDATE())
AND ([Text] LIKE N'%error%' OR [Text] LIKE N'%fail%' OR [Text] LIKE N'%corrupt%' OR [Text] LIKE N'%severity%'
OR [Text] LIKE N'%I/O requests taking longer%' OR [Text] LIKE N'%deadlock%' OR [Text] LIKE N'%paged out%'
OR [Text] LIKE N'%non-yielding%' OR [Text] LIKE N'%stack dump%')
AND [Text] NOT LIKE N'%without errors%' AND [Text] NOT LIKE N'%found 0 errors%' AND [Text] NOT LIKE N'%ERRORLOG%'
AND [Text] NOT LIKE N'Logging SQL Server messages%' AND [Text] NOT LIKE N'%error log%'
ORDER BY LogDate DESC;
-- failed logins (someone using a wrong password, or an app with an old one)
SELECT COUNT(*) AS failed_logins, MAX(LogDate) AS last_seen, [Text]
FROM @log WHERE [Text] LIKE N'Login failed%' AND LogDate > DATEADD(DAY, -7, GETDATE())
GROUP BY [Text] ORDER BY failed_logins DESC;