The SQL Server query below can be used to get a list of all database files (data and transaction log), and their current size and the size that is currently in use. The query uses the dynamic view (DMV) sys.databasefiles, which is present as from SQL Server version 2005.
The query is similar to DBCC SHOWFILESTATS, which also works on SQL Server version prior to 2005, but doesn't include the transaction log files.
The query is similar to DBCC SHOWFILESTATS, which also works on SQL Server version prior to 2005, but doesn't include the transaction log files.
-- Retrieve the occupation of all files of the current database
select file_name(file_id) FileName,
fileproperty(file_name(file_id), 'SpaceUsed') UsedSize,
size TotalSize,
ceiling(fileproperty(file_name(file_id), 'SpaceUsed') * 100.0 / size) UsedPrc,
physical_name FileNameOnDisk
from sys.database_files
--where type = 1 -- (for filtering TransactionLog)
Nenhum comentário:
Postar um comentário