微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sql-server – 如何将数据库从SQL Server 2012移动到SQL Server 2005

如果我需要将数据库sql Server 2012(32位)移动到sql Server 2005(64位),我有哪些选择?

我知道我不能:

>在sql Server 2005上还原数据库的备份
>分离&连接

我知道我可以:

>使用导入数据向导,我在一个数据库上尝试了它,但它只移动数据,甚至这很麻烦,因为我需要做很多工作来创建临时表来维护标识列,重新创建所有FK,索引等.

有更简单的选择吗?

解决方法

您可以按照以下任何方法

注意:如果您正在使用任何新功能,如新数据类型等,那么您必须测试,因为它会抛出错误.

方法1:使用原生工具

>将数据库SCHEMA_ONLY脚本化,并在目标服务器上重新创建一个数据库.以下是截图:

>使用BCP OUT和BULK INSERT插入数据.

以下是将帮助您完成第2部分的脚本.

/************************************************************************************************************************************************
Author      :   KIN SHAH    *********************************************************************************************************************
Purpose     :   Move data from one server to another*********************************************************************************************
DATE        :   05-28-2013  *********************************************************************************************************************
Version     :   1.0.0   *************************************************************************************************************************
RDBMS       :   MS sql Server 2008R2 and 2012   *************************************************************************************************
*************************************************************************************************************************************************/

-- save below output in a bat file by executing below in SSMS in TEXT mode
-- clean up: create a bat file with this command --> del D:\BCP_OUT\*.dat 

select '"C:\Program Files\Microsoft sql Server\100\Tools\Binn\bcp.exe" '-- path to BCP.exe
        +  QUOTENAME(DB_NAME())+ '.'                                    -- Current Database
        +  QUOTENAME(SCHEMA_NAME(SCHEMA_ID))+'.'            
        +  QUOTENAME(name)  
        +  ' out D:\BCP_OUT\'                                           -- Path where BCP out files will be stored
        +  REPLACE(SCHEMA_NAME(schema_id),' ','') + '_' 
        +  REPLACE(name,'') 
        + '.dat -T -E -SSERVERNAME\INSTANCE -n'                         -- ServerName,-E will take care of Identity,-n is for Native Format
from sys.tables
where is_ms_shipped = 0 and name <> 'sysdiagrams'                       -- sysdiagrams is classified my MS as UserTable and we dont want it
and schema_name(schema_id) <> 'some_schema_exclude'                     -- Optional to exclude any schema 
order by schema_name(schema_id)                         



--- Execute this on the destination server.database from SSMS.
--- Make sure the change the @Destdbname and the bcp out path as per your environment.

declare @Destdbname sysname
set @Destdbname = 'destination_database_Name'               -- Destination Database Name where you want to Bulk Insert in
select 'BULK INSERT '                                       -- Remember Tables **must** be present on destination Database
        +  QUOTENAME(@Destdbname)+ '.'
        +  QUOTENAME(SCHEMA_NAME(SCHEMA_ID))+'.' 
        +  QUOTENAME(name) 
        + ' from ''D:\BCP_OUT\'                             -- Change here for bcp out path
        +  REPLACE(SCHEMA_NAME(schema_id),'') + '_'
        +  REPLACE(name,'') 
        +'.dat'' 
        with (
        KEEPIDENTITY,DATAFILETYPE = ''native'',TABLOCK
        )'  + char(10) 
        + 'print ''Bulk insert for '+REPLACE(SCHEMA_NAME(schema_id),'') + '_'+  REPLACE(name,'')+' is done... '''+ char(10)+'go' 
from sys.tables
where is_ms_shipped = 0 and name <> 'sysdiagrams'           -- sysdiagrams is classified my MS as UserTable and we dont want it
and schema_name(schema_id) <> 'some_schema_exclude'         -- Optional to exclude any schema 
order by schema_name(schema_id)

方法2:使用第三方工具

在目标服务器上创建一个数据库.使用Redgate的模式比较和数据比较来创建数据并将其加载到目标服务器中.

注意:我使用过Redgate的架构和数据比较,它们是此类任务的最佳工具,因此如果您使用的是第三方工具,那么我的推荐是Redgate.

原文地址:https://www.jb51.cc/mssql/80000.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐