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’
WHERE spid = 1;
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.