How can I restore a database backup file (.bak) from SQL Server 2012 into SQL Server 2008 Express?

吃可爱长大的小学妹 提交于 2019-12-21 06:50:10

问题


A database that was originally from SQL Server 2008, was restored into SQL Server 2012. A backup from SQL Server 2012 was made and I am trying to restore it on my local SQL Server 2008 Express. However I get an error 'Specified cast is not valid' (SQLManagerUI).

I have generated an SQL Script from 2012 and set it so that it will generate with compatibility to SQL Server 2008. However it is a large sql file, around 700mb.

I recall before that I had tried to run a script of that size before on my local SQLExpress and also got an error.

Is there a way I can get a "large" database from SQL Server 2012 into SQL Server 2008 Express?


回答1:


Thanks to Marc and Aaron for providing the answers.

The quick answer is no, it's not possible to restore a backup file from a higher version to a lower version of SQL Server.

A work around would be to generate the scripts to create the database.

You can target the script generation to a lower version.

Please see comments above for more information.

Links:

Why an SQL Server Database from a higher version cannot be restored onto a lower version of SQL Server?

Create Database in SQL Server 2012, Script and Use in 2008?




回答2:


Couple things to add that might be helpful to folks

When scripting large databases using scripting wizard in SSMS it’s really important to check the execution order and be willing to re arrange it manually. Older versions of SSMS had this problem because they (probably) relied on sp_depends that has a bug.

What I’ve found really useful in such cases are tools like ApexSQL Diff that you can use to read database backups and generate scripts that are in correct execution order.

SQL Server database backup restore on lower version

One thing that none of the methods will catch is the thing Aaron mentioned about using functions specific to higher version.




回答3:


A better option than using the SSMS scripting wizard is to use a similar tool available on Codeplex called SQL Database Migration Wizard - http://sqlazuremw.codeplex.com/releases/view/32334. You want the latest version v4.x to work with SQL Server 2012.

The tool is originally intended to be used for migrating databases between SQL Server and Azure. However the tool works just as well as between SQL Server and SQL Server. The trick is to set SQL Server rather than Azure as the target in the advanced options.

The reason this is a better option than the SSMS scripting wizard is that it uses BCP for the data transfer rather than TSQL and so is much more efficient.



来源:https://stackoverflow.com/questions/10753207/how-can-i-restore-a-database-backup-file-bak-from-sql-server-2012-into-sql-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!