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.
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.
DECLARE @logger TABLE
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.