Click on the banner to learn about and purchase my database training on Azure

SQL Server - How to know how long a specific database has been online

Views: 699 views
Reading Time: 2 minutes

Speak guys!
In this post today, I would like to share a solution I created to answer a question in one of the Telegram groups in which I participate, which was the question of how to know how long a database has been online in SQL Server. That is not how long has the instance been online but how long has a database been online.

To solve this doubt, I thought about using the SQL Server log itself to identify when each database was started and return to the user. The query below will return all banks that are in the last log file, along with the date of the last time the bank was started and the time since then to the current time.


In case you want to analyze the entire startup history of the databases, scanning through all the log files (not just the last one):


In the two solutions presented, you can use the “Database” column to filter the selected banks and I believe that the original question was answered by these 2 scripts.

That's it, guys! I hope you liked this tip. Do you know any other solution to answer this question? Leave it here in the comments 🙂

A big hug and until next time!