Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come faccio a scoprire quali tabelle contengono dati in un file in SQL Server?

Supponendo che tu abbia spostato il tavolo ecc., probabilmente dovrai eseguire:

DBCC SHRINKFILE (MyLogicalFile, EMPTYFILE) --EMPTYFILE is the important bit!!

Vedere DBCC SHRINKFILE

Per controllare (questo è un taglia e incolla di uno script di utilizzo che uso):

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]