April 15, 2008 at 12:31 am
Hi,
Is there any system tables which i can find both (all the database details and Size of the database details)
Smm
April 15, 2008 at 12:36 am
have a look at sys.databases and sys.database_files
---------------------------------------
elsasoft.org
April 15, 2008 at 1:39 am
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
April 15, 2008 at 7:27 am
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
April 16, 2008 at 2:06 am
Is this what your after?
USE master
GO
SELECT size, name, filename
FROM sysaltfiles
GO
April 16, 2008 at 8:01 am
nice. wasn't aware of that one. 🙂
---------------------------------------
elsasoft.org
April 16, 2008 at 8:34 am
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?
April 17, 2008 at 12:40 am
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
April 17, 2008 at 11:50 am
I would recommend using the SQL2005 system view sys.master_files rather than sysaltfiles - if you do not need backward compatibility with 2000.
jg
April 17, 2008 at 12:08 pm
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
April 18, 2008 at 5:27 am
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?
April 18, 2008 at 6:30 am
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.
April 18, 2008 at 12:04 pm
Better names, thanks chandrachurhghosh.
(Unrelated dumb question, why do you and Phil have a "GO" at the end of your queries?)
April 18, 2008 at 6:19 pm
it makes it go faster. 😀
---------------------------------------
elsasoft.org
April 20, 2008 at 3:02 am
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