Sql-server – Reducing database size to restore to SQL Server Express

sql serversql-server-2008-r2

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?

Best Answer

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.