我想删除在SQL Server(2005)一现在假想冗余文件,但是当我尝试删除它,有人告诉我,该文件不是空的。 有谁知道的方法来找出哪些数据仍然是在这个文件中,所以我可以做我需要的任何变化,让我降了吗?
Answer 1:
假设你把桌子等,你可能需要运行:
DBCC SHRINKFILE (MyLogicalFile, EMPTYFILE) --EMPTYFILE is the important bit!!
见DBCC SHRINKFILE
要检查(这是我使用的是使用脚本的cut'n'paste):
SELECT
ds.[name] AS LogicalFileName,
OBJECT_NAME(p.object_id) AS Thing,
SUM(au.total_pages) / 128.0 AS UsedMB,
df.size / 128 AS FileSizeMB,
100.0 * SUM(au.total_pages) / df.size AS PercentUsed
FROM
sys.database_files df
JOIN
sys.data_spaces ds ON df.data_space_id = ds.data_space_id
JOIN
sys.allocation_units au ON ds.data_space_id = au.data_space_id
JOIN
sys.partitions p ON au.container_id = p.hobt_id
WHERE
OBJECTPROPERTYEX(p.object_id, 'IsMSShipped') = 0
GROUP BY
ds.[name], OBJECT_NAME(p.object_id), df.size
ORDER BY
ds.[name]
文章来源: How do I find out what tables have data in a file in SQL Server?