Friday, June 4, 2010

How To Find SQL Server Up Time

Here is the query to Check SQL server UP time Through TrSQL. 

USE master;
GO
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 <> running'
END
ELSE BEGIN
PRINT 'SQL Server and SQL Server Agent both are running'
END

The output would be like below screen-shot:

SQL Server Up Time. How To Check SQL SERVER Uptime Through T-SQL.  How to determine instance uptime. T-SQL to get the SQL Server Service Start time. Determine the Uptime of a SQL Server Instance. How To sum up time field in sql server. Using the UPTIME Utility to Monitor Servers. What's the current uptime of SQL Server?. Tracking Uptime. Continuous Uptime for SQL Server. Server Monitors from up.time. Get SQL Server last restart time and uptime. Uptime Assurance for SQL Server Databases.

0 comments:

Post a Comment