Sql-server – How to restore a SQL Server database and shrink its files at the same time

backuprestoreshrinksql serversql-server-2008

Let's say I have a SQL Server database whose data files have been created with an initial size of 100 GB, but it only contains 10 GB of data. A database backup will then be only 10 GB in size.

I want to restore this backup to a different server (or a different database on the same server), but I don't want it to take the same disk space as the original one (100 GB), which is what happens by default.

I can't shrink the original database before taking a backup (it's a production database, and it needs that much pre-allocated space); I could shrink the restored database after the restore is done, but I would really prefer to have it not take up 100 GB while doing that; besides, in this specific scenario I don't have that much free disk space, so the restore isn't going anywhere.

Is there any way I can restore the database and have it only take up as much space as the actual data it contains?

Best Answer

No, sorry - no way. Restore restores files as they were at the backup. Schinking has to be done after that or before taking the backup.