4

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?

8

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.

2

After you deleted / dropped tables, you have to shrink the database to release unused space.

Then do a backup and ask the client to restore.

Note: If your database is in full recovery and you have never taken a log backup, then take a full backup followed by a log backup and then shrink the database.

Caution: Using SHRINK is not a best and recommended practice., but in some cases you cannot avoid it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.