表大小的差异

时间:2015-02-27 10:42:24

标签: sql-server

我必须检查SQL Server上的大表并尽可能缩小这些表。见下面的选择。 一张表约为18 GB。这个大表包含一个Image类型的列,用于存储二进制数据。

    SELECT 
    s.Name AS SchemaName,
    t.NAME AS TableName,
    p.rows AS Zeilenanzahl,
    SUM(a.total_pages) * 8 AS [Total Storage], 
    SUM(a.used_pages) * 8 AS [Used Storage], 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS [Free Storage]
FROM 
    sys.tables t
INNER JOIN 
    sys.schemas s ON s.schema_id = t.schema_id
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
WHERE   
     t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    [Total Storage] desc, s.Name, t.Name

如果我检查图像区域,我会得到大约700 MB。

  select sum( datalength(Property))
    from dbo.TIF_UserDWProperty

我用这个检查了实际尺寸:

select * into NewTable
  from dbo.TIF_UserDWProperty

新创建的表格大小约为700 MB。

这种差异来自哪里? 我该如何收缩这张桌子? 我尝试过DBCC SHRINKDATABASE但没有成功。

提前感谢。

0 个答案:

没有答案