question

amfineandyou123 avatar image
amfineandyou123 asked

Top 10 Database By Size

I am looking for a script to get the Top 10 database based on size comparing all the SQL Servers (not individual Server databases but comparing all the databases on all the servers and bring the Top 10 DB) in my Environment. Script Category has to be like Last 7 days,1 Month, Last 3 months and Last year.

Can anyone please help me with the script.

sql databasedatabase size
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·

Do you have a system that brings all the required information into one place, or are you after a query that goes out to each server and queries it and then generates the list you need?

And what do you mean by "Script Category has to be like Last 7 days, Last 3 months and Last year"?

If that's what I think it is, then you really do need to have a log of database sizes over time maintained somewhere, rather than just doing a spot-check.

1 Like 1 ·
amfineandyou123 avatar image amfineandyou123 commented ·

Hi Thomas,

Thank you for your response.

I don't have any system to bring everything at one place, so I am expecting a query/script for the same.Actual requirement is to get the Top 10 Database from overall Servers for the last 7 days,last 30 days,last 3 months and last 1 year.it has to be dynamically present.If i run today, then last 1 year from current month or last 7 days from today.

Thanks.

0 Likes 0 ·
ThomasRushton avatar image ThomasRushton ♦♦ amfineandyou123 commented ·

If you want / need to report on sizes of the databases in the past, you need to be logging that information somewhere so you can query it in the future. There's nothing that I know of that will allow you to retrospectively query this...

...except, possibly, for some information in msdb's backup history tables. But that only works if you've kept your backup history for long enough.

1 Like 1 ·

1 Answer

·
lokeshlehkara avatar image
lokeshlehkara answered

Agree with @ThomasRushton, If you need, how the DB's has changed in past 7 days or months or year. Then it needed to be log somewhere. You need to make a small module which will run on daily basis and track the DB size.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.