Using the following script I get all the disk space used by each file in my database:
;with radhe as (
SELECT
DatabaseName = 'my Database', --DB_NAME(),
a.FILEID,
[FILE_SIZE_GB] = CONVERT(DECIMAL(12, 2), ROUND(a.size / 128.000/1024.000, 2)),
[SPACE_USED_GB] = CONVERT(DECIMAL(12, 2), ROUND(fileproperty(a.NAME, 'SpaceUsed') / 128.000/1024.000, 2)),
[FREE_SPACE_GB] = CONVERT(DECIMAL(12, 2), ROUND((a.size - fileproperty(a.NAME, 'SpaceUsed')) / 128.000/1024.000, 2)),
a.NAME, a.FILENAME
FROM dbo.sysfiles a)
select * from radhe
this results:
As you can see on the above picture, the amount of free space inside MyDatabase is high.
I need a copy of this database so that I can test some partitions operations.
Is there a way I can restore this database ignoring the free space in each file?
Basically I will use my "new database" to develop and test something, I would prefer to keep it small.
How could I achieve that?
