Sql-server – open a SQL Server 2008 R2 database in SQL Server 2008 R2 Express

migrationrestoresql serversql-server-2008-r2

This question has probably been asked a dozen times but I couldn't find them here or at SO.

Can I attach/restore a SQL Server 2008 R2 database to my local SQL 2008 R2 Express instance?

Best Answer

Not if you used any persisted Enterprise features. If you used any of such there will be an entry in sys.dm_db_persisted_sku_features and when trying to open/attach/restore this database on any edition lower than Enterprise you will gen an exception and the database won't open. The list possible of persisted SKU features are:

Compression. Indicates that at least one table or index uses data compression or the vardecimal storage format. To enable a database to be moved to an edition of SQL Server other than Enterprise or Developer, use the ALTER TABLE or ALTER INDEX statement to remove data compression. To remove vardecimal storage format, use the sp_tableoption statement.

Partitioning. Indicates that the database contains partitioned tables, partitioned indexes, partition schemes, or partition functions. To enable a database to be moved to an edition of SQL Server other than Enterprise or Developer, it is insufficient to modify the table to be on a single partition. You must remove the partitioned table. If the table contains data, use SWITCH PARTITION to convert each partition into a nonpartitioned table. Then delete the partitioned table, the partition scheme, and the partition function.

TransparentDataEncryption. Indicates that a database is encrypted by using transparent data encryption. To remove transparent data encryption, use the ALTER DATABASE statement. For more information, see Transparent Data Encryption (TDE).

ChangeCapture. Indicates that a database has change data capture enabled. To remove change data capture, use the sys.sp_cdc_disable_db stored procedure.

In addition, for Express edition specifically, the database must be smaller than the maximum database size supported by Express Editions (10Gb). There could be complications if you used any of the service pack specific options like sp_db_increased_partitions but I doubt that's the case.

If your database is clean of all of the above then Express will open it w/o problems. If the source is a Standard Edition then for sure it won't have any of the persisted Enterprise features and the only issue is size.

You need to make sure the SQL Server is the same major release (SQL Server 2008R2, not SQL Server 2008). The patching level (service pack and cumulative updates applied) does not matter as the database format cannot change between minor releases, but it would be recommended to have the Express patched to the latest SP and have the latest CU applied.