Script to check SQL Services uptime

Leave a comment (0) Go to comments

Following SQL Script will list down time for SQL Services are running and Current Status of SQL Server Agent too

SQL Script to SQL Services uptime

-- ***********************************************************************************/ -- Description : Script to check how long the SQL Services were up -- Following script will list down time for SQL Services are running and Current Status of SQL Server Agent too -- Compatibility : 7.0+ -- ***********************************************************************************/ SET NOCOUNT ON DECLARE @crdate

DATETIME, @hr VARCHAR(50), @min VARCHAR(5) SELECT @crdate=crdate FROM sysdatabases WHERE NAME='tempdb' SELECT @hr=(DATEDIFF ( mi, @crdate,GETDATE()))/60 IF ((DATEDIFF ( mi, @crdate,GETDATE()))/60)=0 SELECT @min=(DATEDIFF ( mi, @crdate,GETDATE())) ELSE SELECT @min=(DATEDIFF ( mi, @crdate,GETDATE()))-((DATEDIFF( mi, @crdate,GETDATE()))/60)*60 PRINT 'SQL Server "' + CONVERT(VARCHAR(20),SERVERPROPERTY('SERVERNAME'))+'" is Online for the past '+@hr+' hours & '+@min+' minutes' IF NOT EXISTS (SELECT 1 FROM master.dbo.sysprocesses WHERE program_name = N'SQLAgent - Generic Refresher') BEGIN PRINT 'SQL Server is running but SQL Server Agent <<NOT>> running' END ELSE BEGIN PRINT 'SQL Server and SQL Server Agent both are running' END go


OUTPUT

Script to check  SQL Services uptime when was the sql service started sql server uptime how to check sql server start time check how long sql services were running

Tags : sql server uptime, how to check sql server start time, check how long sql services were running, when was the sql service started

EOF - Script to check SQL Services uptime, SQL Server 2012 , 2008 R2 , 2008 , 2005 , 2000

Leave a Reply

Your email address will not be published. Required fields are marked *


*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.