Alternate way to find database size

Alternate way to find database size

I like the concept of Madhusudan Naidu Gundapaneni's tip, Find the size of every database. This is a simple variation on his theme that slits out the log and data file sizes.

sp_msforeachdb 
  'SELECT ''?'' DatabaseName
  , case when status & 0x40 = 0x40 then ''data'' else ''log'' end FileType
  , cast(((sum(size))*0.0078125) as decimal(15,2)) [FileSize (MB)] 
    FROM "?"..SYSFILES GROUP BY status ORDER BY status desc'
  

Reader Feedback

Craig S. writes: I ran this script but I think the log and data sizes are reversed? At least that's the way it came up on my SQL Server.

The author writes: He's right. Here's the correct code:

sp_msforeachdb

    Requires Free Membership to View

    By submitting your registration information to SearchSQLServer.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSQLServer.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

Premium Access

Register now for unlimited access to our premium content across our network of over 70 information Technology web sites.
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

This was first published in February 2005

'SELECT ''?'' DatabaseName , case when status & 0x40 = 0x40 then ''log'' else ''data'' end FileType , cast(((sum(size))*0.0078125) as decimal(15,2)) [FileSize (MB)] FROM "?"..SYSFILES GROUP BY status ORDER BY status desc'

For More Information

  • Feedback: E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free SQL Server tips and scripts.
  • Tip contest: Have a SQL Server tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our SQL, database design, SQL Server, DB2, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical SQL Server questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: SQL Server tips, tutorials, and scripts from around the Web.

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.