目前我的数据库大小为24MB,只有5MB数据,我试图在发布后计算数据库的未来增长。对我来说最明显的方法是从表中取一个记录大小并将其乘以虚数。搜索后我找到了几个脚本,但是我得不到合适的结果。
根据这个脚本,我获得了大约2.5KB的一条记录的值,似乎戒了。
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM
sys.tables t
INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN
sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN
sys.schemas s ON t.schema_id = s.schema_id
WHERE
t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.OBJECT_ID > 255
GROUP BY
t.Name, s.Name, p.Rows
ORDER BY
t.Name
这个脚本向我展示了表中每条记录的大小,在我的例子中它是77字节看起来更真实,同时让我完全迷惑。
declare @table varchar(20)
declare @idcol varchar(10)
declare @sql varchar(1000)
set @table = 'Compliants'
set @idcol = 'Id'
set @sql = 'select ' + @idcol +' , (0'
select @sql = @sql + ' + isnull(datalength(' + name + '), 1)'
from syscolumns where id = object_id(@table)
set @sql = @sql + ') as rowsize from ' + @table + ' order by rowsize desc'
exec (@sql)
我需要这个计算来确定未来的超速,如果没有估计数据库大小在发布后会如何增加,这是不可能的。有没有技术可以这样做?