dcsimg
 

How to Programmatically Identify When Your SQL Server Was Last Started

Monday Apr 2nd 2018 by Greg Larsen

Greg Larsen shows you a quick trick to programmatically script a way to identify when SQL Server was last started.

Where do you go to find the last time SQL Server was started?  I’m guessing you might have gone to the ERRORLOG file and reviewed it to determine when SQL Server started.  That method will work.  But what if you programmatically want to script a way to identify when SQL Server was last started.  How would you do that?

There is a simple TSQL way to programmatically identify the last time SQL Server was started.  Here is the code to accomplish this:

SELECT login_time FROM sys.dm_exec_sessions WHERE session_id = 1;

See all articles by Greg Larsen

Home
Mobile Site | Full Site