How to migrate a SQL Server database to a lower version

本文介绍如何将 SQL Server 2012 的数据库降级到 SQL Server 2008 R2。通过使用 SQL Server Management Studio 的 Generate Scripts 向导来创建数据库脚本,并在较低版本的 SQL Server 中运行这些脚本来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.mssqltips.com/sqlservertip/2810/how-to-migrate-a-sql-server-database-to-a-lower-version/


Problem

After recently upgrading a SQL Server instance to SQL Server 2012 a few days ago, you noticed that your application is not functioning properly. You decided to roll back the upgrade by downgrading the SQL Server database engine to SQL Server 2008 R2.  After the downgrade of the database engine, you are unable to attach the databases or restore the backups of the databases, even though the database compatibility level is set to the downgraded version of SQL Server. You receive the following error message, when you attempt to restore the database:

Msg 1813, Level 16, State 2, Line 1 
Could not open new database 'DatabaseName'. CREATE DATABASE is aborted. 
Msg 948, Level 20, State 1, Line 1 
The database 'DatabaseName' cannot be opened because it is version 655. This server supports version 611 and earlier. A downgrade path is not supported.

This error message is generated because SQL Server automatically upgrades the database, when you restore or attach the database from lower version to higher version.  SQL Server does not allow you to restore or attach a database from a higher version of SQL Server to a lower version  of SQL Server. In this tip, we will look at a one time procedure which we can follow to downgrade the database from a higher version (SQL Server 2012) of SQL Server to a lower version (SQL Server 2008 R2) of SQL Server.

Solution

The error message in the problem statement occurs because the SQL Server database files (*.mdf, *.ndf and *.ldf) and backups are not backward compatible.  Backward compatibility is why we cannot restore or attach a database created from a higher version of SQL Server to a lower version SQL Server. However, there are a few options that can help us to downgrade the database from a higher version of SQL Server to a lower version SQL Server. These options include:

  • Generate Scripts wizard of SQL Server Management Studio
  • SQL Server Integration Services
  • Custom scripting and BCP

In this tip we will use the Generate Scripts wizard of SQL Server Management Studio.  Here are the basic steps we need to follow:

  • Script the database schema in higher version of SQL Server by using the Generate Scripts wizard of SQL Server Management Studio interface.
  • Connect to the lower version of SQL Server, and then run the SQL scripts that were generated in the previous step, to create database schema and copy data.

In the next section, I will demonstrate the steps for downgrading a SQL Server 2012 database to SQL Server 2008 R2 database.

Note: For demonstration purpose, I'll be downgrading the OUTLANDER database hosted on my SQL Server 2012 instance (IITCUK\DEV01) to SQL Server 2008 R2 instance (IITCUK\SQLSERVER2008).

Step-by-Step Demo: Downgrading a SQL Server 2012 database to SQL Server 2008 R2

Step-1: Script the schema of the OUTLANDER database on the SQL Server 2012 instance (IITCUK\DEV01) using theGenerate Scripts wizard of the SQL Server Management Studio interface.

In Object Explorer connect to IITCUK\DEV01, right-click OUTLANDER database, expand Tasks and choose"Generate Scripts...".

In Object Explorer, right-click OUTLANDER database, expand Tasks and choose

This launches Generate and Publish Scripts wizard. Click Next, to skip the Introduction screen and proceed to theChoose Objects page.

SQL Server Management Generate and Publish Scripts Wizard - Introduction Screen

On the Choose Objects page, choose option "Script entire database and all database objects", and then clickNext to proceed to "Set Scripting Options" page.

Choose option Script entire database and all database objects in the SQL Server Management Studio Generate Scripts Wizard

On the Set Scripting Options page, specify the location where you want to save the script file, and then choose theAdvanced button.

Choose option Specifying scripting options in the SQL Server Management Studio Generate Scripts Wizard

In Advanced Scripting Options dialog box, set Script TriggersIndexes and Primary Key options to TrueScript for Server Version to SQL Server 2008 R2, and Types of data to script to Schema and Data.  This last option is key because this is what generates the data per table.

Choose option Set scripting options including scripting the Schema and Data

Once done, click OK, to close Advanced Scripting Options dialog box and return to Set Scripting Options page. InSet Scripting Options page, click Next to continue to Summary page.

After reviewing your selections on Summary page, click Next to generate scripts.

Generate and Publish Scripts - Summary Interface

Once scripts are generated successfully, choose the Finish button to close the Generate and Publish Scripts wizard.

Generate and Publish Scripts wizard iterating through each object

Step-2: Connect to the SQL Server 2008 R2 instance (IITCUK\SQLSERVER2008), and then run the SQL scripts that were generated in Step-1, to create the OUTLANDER database schema and copy its data.

In Object Explorer connect to IITCUK\SQLServer2008, then in SQL Server Management Studio, open the SQL Server script you saved in Step-1.

SSMS


Opening SQL Script to install OUTLANDER database


Opening SQL Script to install OUTLANDER database

Modify the script, to specify the correct location for the OUTLANDER database data and log files. Once done, run the script to create the OUTLANDER database on IITCUK\SQLServer2008 instance.

Restoring OUTLANDER database

Upon successful execution, refresh the Database folder in Object Explorer. As you can see in the following imageOUTLANDER database has been successfully downgraded.

Verifying OUTLANDER database downgrade
Next Steps
  • To avoid this issue, always make sure that you perform a full backup of the database before you upgrade the SQL Server and database to a higher version of SQL Server.  In addition, be sure to thoroughly test the application prior to releasing the application to the users.
  • Consider this downgrade option as your last option to rollback from an upgrade because the time and storage needed can be very large.
  • With a very large database be sure you have sufficient storage to support the data needs.
  • Be sure to verify row and object counts as well as test your application before releasing to production.
  • Additional Resources:

### 回答1: 如果你想要在日本获得永久居留身份,你需要先申请日本的签证。有许多不同类型的签证可供选择,具体取决于你在日本的目的和活动。 其中一种常见的签证类型是工作签证,这通常需要你有一份在日本的工作合同,并且你的雇主必须向当地的劳动局申请这种签证。你也可以考虑申请留学签证,这通常需要你在日本的一所大学或学校学习。 如果你已经在日本拥有了某种签证,并且希望获得永久居留身份,你可以向日本的公民政策局申请永久居留身份。申请需要满足一些条件,包括入籍时间、工作情况、居住时间等。你可以通过查询日本政府的网站或者咨询日本领事馆了解更多信息。 ### 回答2: 要想移民日本并获得永久居民身份,以下是一些建议: 1. 具备合适的签证:首先,获得合适的签证是移民日本的第一步。常见的签证类型包括工作签证、学生签证、投资签证等。可以根据个人情况选择最适合自己的签证类型。 2. 学习日本语言和文化:日本是一个讲究礼仪和文化传统的国家。学习日本语言和了解日本文化不仅可以帮助适应当地生活,还有助于融入社会并增加与日本人交流的机会。 3. 获得就业机会:在日本找到工作并获得雇主的赞助可以增加移民的机会。具备相关技能和经验,通过良好的求职准备和积极的面试表现,增加成功找到工作的机会。 4. 掌握技术或专业知识:日本对于高技能或专业知识的人才有较高的需求。通过持续学习和培训,提升自己在特定领域的竞争力,增加被日本雇主看中的机会。 5. 遵守法律和履行义务:在日本合法居住并申请永久居民身份需要遵守当地的法律法规,并按时履行纳税义务等。保持良好的行为记录和公民意识会有助于积累社会信用和获得永久居民身份。 需要注意的是,移民日本并获得永久居民身份需要时间和努力。每个人的情况和背景不同,建议咨询专业移民律师或相关部门,以获取更详细和个性化的建议。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值