mssql sqlserver 检索errorlog的方法分享


摘要:
下文将分享检索errorlog日志的方法


实现思路:
将errorlog读取,并存入至指定物理表,然后对物理表进行select 查询检索,找出我们所需的信息,如下所示:

     CREATE TABLE #tmp_errorlog  (
       writeDate DATETIME
     , ProcessInfo VARCHAR(256)
     ,MessageText VARCHAR(max)
    )
GO
INSERT #tmp_errorlog  
EXEC sp_readerrorlog
GO
SELECT e.writeDate
    ,e.ProcessInfo
    ,e.MessageText
FROM #tmp_errorlog e
WHERE (
        e.MessageText LIKE 'DBCC CHECKTABLE%'
        AND e.MessageText LIKE 'DBCC CHECKDB%'
        AND e.MessageText LIKE '%found%'
        AND e.MessageText LIKE '%errors%'
        AND e.MessageText NOT LIKE '%found 0 errors%'
        )
 
DROP TABLE #tmp_errorlog