我正在尝试通过编程来监控SQL Server数据库的大小,以便我的Web应用程序的管理员部分可以报告它,并且我可以使用它来执行一些清理存储过程,以清除日志文件等。
我使用以下代码来计算表格的大小,以符合SO建议:
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 nameSELECT SUM(CONVERT(INT, SUBSTRING(data, 1, LEN(data)-3))) FROM
#tDROP TABLE #t
当我对我的小样本数据库运行此操作时,得到的总和值约为6.8兆字节。 当我查看我的数据库属性时,显示为15.5兆字节。
I have the following questions:
1. What else can make up the difference?
2. Can this difference be described as "overhead", which will only grow at a fraction of the pace as other data grows (rough estimate is all I need for this).
3. Stored Procedures, Functions, Views, Triggers are in this "overhead" space? Is there a way to calculate these?
4. Is there another way to get the WHOLE database size? I really just want a simple way to get the REAL size.