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.

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...