March 16, 2009 at 8:34 am
How could i list size of all databases in (MB/GB) in a server.
March 16, 2009 at 8:36 am
sp_helpdb?
it lists the DBname, DBSize, and some other stats.
-- Cory
March 16, 2009 at 8:40 am
i know sp_helpdb will give that info but i need only few db's and thier size in a single result set for a report.
March 16, 2009 at 8:49 am
sp_msforeachdb @command1 = 'use ? select ''?'', name, size*8/1024 as SizeInMB from sysfiles'
You would have to insert this into a temp table and select out of that - or - you could use the following;
SELECT db_name(database_id) AS DatabaseName, sum((size*8)/1024) as 'All db Size' from sys.master_files group by db_name(database_id)
David
@SQLTentmaker“He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot
March 16, 2009 at 8:53 am
Mike,
I'm confused, you asked for all databases, then you say a few. What exactly are you trying to do?
You can also grab the query from sp_helpdb and filter out system dbs if you want that.
March 16, 2009 at 9:15 am
I am using this for table count in each db, is there a way i can do it on whole server for each dabase listing table count by server by table name.
SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
AND
si.id = OBJECT_ID(so.name)
GROUP BY
so.name
ORDER BY
2 DESC
March 16, 2009 at 5:17 pm
Try this. Note, I've updated your join syntax to bring it into the 21st century.
DECLARE @sql VARCHAR(1000)
SET @sql = 'SELECT ''?'', so.name, MAX(si.rows)
FROM sysobjects so
JOIN sysindexes si on so.id = si.id
WHERE so.xtype = ''U''
GROUP BY so.name
ORDER BY 2 DESC'
CREATE TABLE #t ([Database] VARCHAR(255), [TableName] VARCHAR(255), [RowCount] INT)
INSERT #t
EXEC sp_msforeachdb @sql
SELECT * FROM #t ORDER BY 1, 3 DESC
DROP TABLE #t
March 16, 2009 at 8:12 pm
Mike Levan (3/16/2009)
How could i list size of all databases in (MB/GB) in a server.
Mike Levan (3/16/2009)
I am using this for table count in each db, is there a way i can do it on whole server for each dabase listing table count by server by table name.SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
AND
si.id = OBJECT_ID(so.name)
GROUP BY
so.name
ORDER BY
2 DESC
Heh... Ok Mike... which one do you really want? 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
March 31, 2009 at 11:54 am
using the same script how would i compare 2 identical databases on diffrent servers. I would like to find out if there is any difference in the numbers of tables and the rowcount from both the database.
March 31, 2009 at 12:06 pm
Redgate SQLCompare. You can download a 14-day trial from their website.
March 31, 2009 at 12:54 pm
Google "Open DBDiff" for schema comparisons
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply