views:

8903

answers:

4

SQL Server 2005/2008 Express edition has the limitation of 4 GB per database. As far as I known the database engine considers data only, thus excluding log files, unused space, and index size.

Getting the length of the MDF file should not give the correct database size in terms of SQL Server limitation. My question is how to get the database size?

+4  A: 

sp_spaceused

David B
sp_spaceused takes into account the log file size, so if you have a really small db and a really big log file, the result from sp_spaceused will be misleading when trying to determine how close you are to the 4GB limit.
Lamar
The question explicitly asks for log file to be included. Is he misguided about log file applying toward the 4 GB limit?
David B
+4  A: 

In SQL Management Studio, right-click on a database and select "Properties" from the context menu. Look at the "Size" figure.

Ian Nelson
+4  A: 

According to SQL2000 help, sp_spaceused includes data and indexes.

This script should do:

CREATE TABLE #t (name SYSNAME, rows CHAR(11), reserved VARCHAR(18), 
data VARCHAR(18), index_size VARCHAR(18), unused VARCHAR(18))

EXEC sp_msforeachtable 'INSERT INTO #t EXEC sp_spaceused ''?'''
-- SELECT * FROM #t ORDER BY name
-- SELECT name, CONVERT(INT, SUBSTRING(data, 1, LEN(data)-3)) FROM #t ORDER BY name
SELECT SUM(CONVERT(INT, SUBSTRING(data, 1, LEN(data)-3))) FROM #t
DROP TABLE #t
devio
+8  A: 

sp_helpdb

no looping needed, unlike sp_spaceused.