SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

When Did SQL Server Restart?

I saw Joe Webb’s post, and then Gethryn Ellis’ post as well on when SQL Server last restarted. It’s something that can be handy when troubleshooting and trying to figure out what’s going on with SQL Server.

I’ve also used it to track potential issues as well, like when others might be changing things on the server, like patching, altering configuration (memory) or something else.

So how do you do it? Here’s what I’ve done. I’ve used before. I use this function in SQL Server to read the error log in T-SQL.

exec xp_readerrorlog


That’s good since the first timestamp here is the time that SQL Server started. It’s before the databases are even accessible. Now I need to grab that one date. I’ve wrapped this in a small bit of code.

    dt datetime,
    Process varchar(50),
    txt varchar(MAX)
INSERT @logger exec xp_readerrorlog
SELECT TOP 1 dt FROM @logger

I can store this value in a table, which is what I usually do, and then I can watch it over time, set an alert on it in a daily report, whatever.

Not perhaps as elegant as some of the other solutions, but one that’s worked for me.

The Voice of the DBA

Steve Jones is the editor of SQLServerCentral.com and visits a wide variety of data related topics in his daily editorial. Steve has spent years working as a DBA and general purpose Windows administrator, primarily working with SQL Server since it was ported from Sybase in 1990. You can follow Steve on Twitter at twitter.com/way0utwest


Posted by Seth Lynch on 4 May 2010


I have a monitoring job that pulls in the dates databases were created - I use the date for TempDB to show me a report of when SQL server restarted. I use this to email me each morning with server up time - if it is <1 then I start investigating.

I have this across dev, test, and live – I really use it to keep track of when developers have created new databases so I can give it a quick once over.


Posted by Anonymous on 4 May 2010

Pingback from  Eminem takes uplifting new tack | wwwyahoo_yahoomail_video_women

Posted by dave turpin on 5 May 2010

Steve, I use sp_helpdb to capture the create date on tempdb, which is the date/time duple of the last service startup.

Leave a Comment

Please register or log in to leave a comment.