T-SQL – Checking SQL Server Uptime

T-SQL – Checking SQL Server Uptime

Microsoft SQL Server keeps tracks of all the processes, when they start and when they end, in the sys.sysprocesses system view of the master database. To check the uptime of SQL Server using T-SQL, use the below script.

SELECT login_time AS ‘Started’,


DATEDIFF(DAY, login_time, CURRENT_TIMESTAMP)
AS ‘Uptime in days’

FROM
sys.sysprocesses

WHERE spid = 1;

Go

 

login_time is the time the process logged into the server.
spid = 1 indicates a system processes, and that’s the time when the Microsoft SQL Server started.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s