Get the SQL Server instance start time
Three T-SQL queries to get the last start time of a SQL Server instance, directly or through indirect indications.
These three queries return the time the SQL Server instance started, that is the date of the last restart of the service, from different dynamic management views.
SELECT sqlserver_start_time FROM sys.dm_os_sys_info;
SELECT login_time FROM sys.dm_exec_sessions WHERE session_id = 1;
SELECT create_date FROM sys.databases WHERE name = 'tempdb';
Explanation
sys.dm_os_sys_inforeturns the instance start time directly.sys.dm_exec_sessions(session 1) andsys.databases(creation date oftempdb) give indirect indications.tempdbis recreated at each instance start.
Notes
- The first query is the direct source. The other two can differ from the exact start time.