Home > DeveloperSection > Forums > How we can Reduce DB size to restore to SQL Server Express
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    September-23-2015 1:38 AM

 MSSQL Server Database  MSSQL Server 
Ratings:


 1 Reply(s)
 459  View(s)
Rate this:
I have a SQL Server 2008 R2 database, about 15 GB.

I want to copy it for a partner, who is using SQL Server 2008 R2 Express.

I deleted many tables and rows, and now I am sure that the data is smaller than 2 GB.

I make a backup, send to the partner, he tries to restore it but he receives an error:

CREATE DATABASE or ALTER DATABASE failed because the resulting cumulative database size would exceed your licensed limit of 10240 MB per database
What did I do wrong?


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Posted on    September-23-2015 6:49 AM

The sum of the file size for all data files has to be < 10 GB, not the amount of data in the file. So, deleting data from some tables, or even dropping some tables, does not solve problem. You need to shrink the file, something like this:

ALTER DATABASE mydb MODIFY FILE (name = N'logical_name', size = 2048MB);
This will fail if the database size can't be reduced to 2 GB. You may need to first issue:

DBCC SHRINKFILE(logical_name, 2048);
If you use any form of SHRINKFILE, then you'll need to validate in File Explorer that the data file(s) are actually as small as you think (because shrink operations will shrink as much as they can, and stop silently when they can't reach your target size).

Then take a backup, then restore on SQL Server Express (with @@VERSION the same or higher than the source, of course).

You may come across other issues, for example if you have used any features that aren't supported on Express.

Don't want to miss updates? Please click the below button!

Follow MindStick