SQL: Export a SQL Server 2008 DB to SQL Server 2005

Since the 2008 version uses a different format for .bak files, a backup done in 2008 cannot be restored from 2005. A possible workaround is is creating, in 2008, a Script targeted at 2005, and run that scrit in 2005. The steps:

  1. Open Managment Studio 2008 and connect to the instance in which the DB we wanna export is.
  2. Right click the database, and hit Tasks->Generate Scripts.
  3. Hit Next in the initial Dialog.
  4. Check "Script all objects in the selected database" before hitting Next. This guarantees that not only the schema is exported, but the contents too.
  5. In the next dialog, we have lots of options. The ones we have to set before hitting Next are the following:
    • Script for Server Version : SQL Server 2005.
    • Script Data : True.
    • If the DB to export wasn't created in the 2005 server, which is usually the case, set 'Script Database Create' to 'True'.
  6. Select 'Script to File' so that we create the .sql script. We can set the path where we want Management Studio to drop it in a textbox. Also, check the 'Single file' option so that the script is only one file. Hit 'Next'.
  7. In this dialog we can see a summary of what the script does. Check it's coherent before clicking Finish.
  8. Once Management Studio is done, open it and check for lines like these:
    CREATE DATABASE [Northwind] ON PRIMARY
    
    (NAME = N'Northwind', FILENAME =
    N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATAorthwnd.mdf' ,
    SIZE = 3328KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
    
    LOG ON
    
    (NAME = N'Northwind_log', FILENAME =
    N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATAorthwnd.ldf' ,
    SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
    
    GO
    Correct the paths so that they match the ones that the target server (2005) uses.
  9. It might be necessary to comment out lines like these; in my case, it wasn't necessary:
    --EXEC sys.sp_db_vardecimal_storage_format N'Northwind', N'ON'
    --GO
  10. Finally, copy the .sql file to the machine where the 2005 server lives, open it from Management Studio 2005 (File->Open) and hit Execute. In my particular case, I got some errors when the script tried to create some users that already existed, but that wasn't fatal. The script continued and brought me all the tables and their rows.
Reference: SQL Server Central

Comments

Popular posts from this blog

VB.NET: Raise base class events from a derived class

Apache Kafka - I - High level architecture and concepts

Upgrading Lodash from 3.x to 4.x