Size and Name of all Databases

  • Hi,

    Is there any system tables which i can find both (all the database details and Size of the database details)

    Smm

  • have a look at sys.databases and sys.database_files

    ---------------------------------------
    elsasoft.org

  • i have tried with both but select * from sys.databases

    it is not giving details about size,

    and the other one not giving all the db size details,we need to run in each DB

  • you could do something like this:

    declare @sql nvarchar(4000)

    declare @name sysname

    declare @t table (dbname sysname, filename sysname)

    -- loop over all databases using a cursor/while loop, which I am too lazy to do here...

    set @name=N'AdventureWorks' -- set this in your loop, don't hard code as here

    set @sql=N'select ''' + @name +''', physical_name from ' + quotename(@name) + '.sys.database_files'

    insert @t exec(@sql)

    select * from @t

    ---------------------------------------
    elsasoft.org

  • Is this what your after?

    USE master

    GO

    SELECT size, name, filename

    FROM sysaltfiles

    GO

  • nice. wasn't aware of that one. 🙂

    ---------------------------------------
    elsasoft.org

  • If you like "pretty" - make sure to download the Performance Dashboard reports from MS' download site. Has a very nice databases summary report (sizes and more)

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • sp_spaceused

    This system stored procedure will return the size statistics for the current database context in which it is running. It is very useful for returning ad hoc information regarding database or table sizes within the database; however, it is not very friendly for reporting purposes. It is possible to capture the information for each database through a script, but it would require the use of a user-defined cursor.

    - Manish

  • I would recommend using the SQL2005 system view sys.master_files rather than sysaltfiles - if you do not need backward compatibility with 2000.

    jg

  • The script on the link below produces a detailed analysis of the file size information for all databases on a SQL Server.

    Get Server Database File Information

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=89058

    Totals for the following are produced:

    File Details

    Total by Database and File

    Total by Database and Filegroup

    Total by Database and Filegroup Type

    Total by Disk, Database, and Filepath

    Total by Disk and Database

    Total by Database

  • Phil Knott (4/16/2008)


    Is this what your after?

    USE master

    GO

    SELECT size, name, filename

    FROM sysaltfiles

    GO

    Thank you for that (I like clean and simple!)

    When I run it, it fails to show the name of my primary database, and instead lists the servername (_dat and _log). Is this another situation (like configuration/schema changes history) where an original name is preserved instead of the current name?

  • Use the following script -

    USE master

    GO

    SELECT B.[Name] AS [Database Name (Logical)],

    A.[Name] AS [Physical Name],

    A.[filename] AS [File Path],

    A. AS [File Size]

    FROM sysaltfiles A

    INNER JOIN sys.databases B

    ON A.DBID=B.Database_ID

    --WHERE B.[Name]='PRACTICE'

    GO

    Note: You can use a specific database name to retrive relevant information

    Chandrachurh Ghosh
    DBA – MS SQL Server
    Ericsson India Global Services Limited
    Quality is not an act, it is a habit.

  • Better names, thanks chandrachurhghosh.

    (Unrelated dumb question, why do you and Phil have a "GO" at the end of your queries?)

  • it makes it go faster. 😀

    ---------------------------------------
    elsasoft.org

  • Try....

    Sp_helpdb

    and

    sp_msforeachdb 'sp_helpdb [?]'

    Regards

    shashi kant chauhan 🙂

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic. Login to reply