Sign up ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

What are my options if I need to move a database from SQL Server 2012(32bit) to SQL Server 2005(64bit)?

I know I cannot:

  • restore a backup of the database on SQL Server 2005
  • detach & attach

I know I can:

  • use import data wizard, and I tried it on one database, but it only moves data, and even that was troublesome as I needed to do a lot of work creating temp tables to maintain identity columns, recreating all FKs, indexes etc.

Is there an easier option?

share|improve this question
Right click on the database, script to file/new window. Create in 2005 instance. At this point you should have the structure in place (assuming you've used nothing new from 2008+) At this point, you have to fill your tables. I'm not aware of any ETL tool that is going to interrogate your data structure and identify the order tables should be loaded. – billinkc Dec 15 '13 at 15:29
The easier option would be to upgrade the destination to 2012, to be honest. – Aaron Bertrand Dec 15 '13 at 15:59

1 Answer 1

You can follow any method below :

Note: If you are using any new features like new data types, etc then you have to test out as it will throw errors.

METHOD 1: Using Native Tools

  1. Script out the database SCHEMA_ONLY and recreate an empty database on the destination server. Below are the screenshots :

    enter image description here

    enter image description here

    enter image description here

  2. Use BCP OUT and BULK INSERT to insert data.

Below is the script that will help you with Part 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(name) 
        + ' from ''D:\BCP_OUT\'                             -- Change here for bcp out path
        +  REPLACE(SCHEMA_NAME(schema_id),' ','') + '_'
        +  REPLACE(name,' ','') 
        with (
        DATAFILETYPE = ''native'',  
        )'  + 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)

Method 2 : Using Third Party Tools

Create a blank database on destination server. Use Redgate's schema compare and data compare to create and load data into the destination server.

Note: I have used Redgate's schema and data compare and they are the best tools for such type of task and hence if you are using 3rd party tools, then my recommendation would be Redgate.

share|improve this answer
+1 but keep in mind that there are certain things that just won't work at the destination (and I'm not sure how graceful 3rd party tools will handle all of that). Objects like SEQUENCEs, code like OFFSET / FETCH, LAG / LEAD, etc. – Aaron Bertrand Dec 15 '13 at 20:17
@AaronBertrand Agreed and hence I put the disclaimer to first test it thoroughly. Downgrading is always a pain !! – Kin Dec 15 '13 at 20:22

protected by Kin Aug 10 at 15:49

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.