Wednesday, July 11, 2012

Find when SQL Server was last started

When ever SQL Server is (re)started ‘TempDB’ gets recreated. So the below query should give us the time of when ‘SQL Server’ was last started.

Select create_date from sys.databases where [name] = 'tempdb'

When a SQL Server starts all the tasks which it initiates makes an entry in sysprocesses table with its ‘login time’. That said, all we need to do is find the least login_time which has got recorded in that table!
1. Select min(login_time) from master.dbo.sysprocesses 
2. Select login_time from master.dbo.sysprocesses where spid = 1 
3. Select login_time from sys.dm_exec_sessions where session_id = 1

No comments:

Post a Comment