SQL Server logs and agent error days generally after the instance restarts itself, assuming that the instance has not been restarted for a long time, it will probably accumulate too many logs, inconvenient to view.
To view the error log size:
--View log size exec xp_enumerrorlogs--sqlserver error log exec xp_enumerrorlogs 1--sqlserver error log exec xp_enumerrorlogs 2--agent Log
Log switchover: (Requires permission: Member of the sysadmin fixed server role)
--"SQL Server log" toggle exec msdb.dbo.sp_cycle_errorlog--"Agent error log" toggle exec Msdb.dbo.sp_cycle_agent_errorlog
Log View:
--Log view exec Xp_readerrorlog @FileNum, @Type, @SearchText1, @SearchText2, @StartTime, @EndTime, @order @filenum: Log number @Type : Query type (1:sql Server log; 2: Agent error log) @SearchText1: Search text @searchtext2: Search text (with @SearchText1 for "and" relationship) @StartTime: Log query start time @start Time: Log query end @order: Time sort (ASC or DESC)
Demo Sample:
--View current "SQL Server log" deadlock exec xp_readerrorlog 0,1, ' deadlock victim ', NULL, ' 2015-06-01 ', ' 2015-06-30 ', ' desc ' --View second "SQL Server Log" text has "error" and "Server" row exec xp_readerrorlog, ' Error ', ' Server ', ' 2015-06-01 ', ' 2015-06-30 ', ' ASC ' --View the current "Agent error Log" text with "error" in the line exec Xp_readerrorlog 0, 2, ' Error ', null,null,null, ' desc '
SQL Server error log switching and viewing