How to restore a SQL Server database backup to an older version of SQL Server

If there was need to restore a SQL Server database backup to an older version of SQL Server there was “greeting” with error messages along the lines of:

Msg 3169, Level 16, State 1, Line 1
Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally.

or

Msg 3241, Level 16, State 7, Line 1
Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally.

and the attempted backup restore would fail.

The reason for this behavior is that by default SQL Server doesn’t allow restoring a database backup to an older version of SQL Server, regardless of the compatibility level of the database the backup was taken from.

However, there is a way to restore a database to a newer SQL Server version.

If there is access to the live database backup was taken from:

  1. Start SQL Server Management Studio and connect to the instance where the database resides
  2. In the database context menu, navigate to Tasks | Generate Scripts…. This will invoke the Generate and Publish Scripts wizard
  3. In the Introduction step of the wizard click Next
  4. In the Choose Objects step of the wizard make sure that the Script entire database and all database objects option is selected and click Next
  5. In the Set Scripting options step of the wizard:
    1. Select the Save scripts to a specific location option
    2. Specify whether the database objects and data will be scripted to a single file, multiple files, as well as the path and encoding of the generated scripts
    3. Click Advanced
    4. In the Advanced Scripting Options dialog that will appear:
      • Specify the version of the SQL Server you need the database restored to in the Script for Server Version option
      • In the Script for Server Version option, specify Schema and data
      • Set the following options to True:
        • Script Logins
        • Script Full-Text Indexes
        • Script Triggers
      • Click OK
  6. Click Next
  7. In the Summary step of the wizard, click Next
  8. In the Save or Publish Scripts step of the wizard click Finish
  9. Execute the generated SQL script(s) against the older SQL instance

Although the procedure listed above should work:

  1. It doesn’t migrate all of the database objects (e.g. sequences or queues)
  2. It might fail if your database contains dependencies which SQL Server fails to recognize (e.g. dependencies to databases residing on linked servers)

To top it all, if there is no access to the original database for any reason (e.g. migrating the database to an off-site location with no network connectivity), the above procedure is inapplicable in that scenario

Does that mean a backup cannot be restored to an earlier SQL Server version? No, far from it – this is where ApexSQL Diff and ApexSQL Data Diff come into play

ApexSQL Diff is a SQL Server database comparison and synchronization tool which detects differences between database objects and resolves them without errors. It generates comprehensive reports on the found differences and can automate the synchronization process between live and versioned databases, backups, snapshots and script folders

ApexSQL Data Diff is a SQL Server data comparison and synchronization tool which detects data differences and resolves them without errors. It can compare and sync live databases and native or natively compressed database backups and generate comprehensive reports on the detected differences

To restore the backup to and older SQL Server version

  1. On the target SQL instance, create an empty database to hold the data and objects restored from the backup
  2. Start ApexSQL Diff
  3. Click New in the Project management dialog

    Project management dialog

  4. In the Source pane:
    • Select Backup from the Type drop-down box
    • Click Add file(s) and navigate to the folder where the backup file resides
    • Select the backup and click Open
  5. In the Destination pane:
    • Select Database from the Type drop-down box
    • Specify the SQL instance where the databaseto which to recover the objects reside from the Server drop-down box
    • Specify the authentication method for that SQL instance (and a valid set of credentials if you chose SQL Server authentication)
    • Specify the name of the database to which to recover the objects in the Database drop-down box
  6. Click Compare
  7. Select all the objects listed in the Main grid

    ApexSQL Diff Main grid

  8. Click Synchronize in the Actions region of the ribbon’s Home tab
  9. Click Next in the Synchronization direction step of the Synchronization wizard
  10. Click Next in the Dependencies step of the Synchronization wizard

    Synchronization wizard - Dependencies

  11. Review the synchronization summary and warnings, if any, and click Next

    Synchronization summary and warnings dialog

  12. In the Output options step of the Synchronization wizard select Synchronize a database
  13. Click Finish
  14. Start ApexSQL Data Diff
  15. Click New in the Project management dialog

    Click New in the Project management dialog

  16. In the Source pane:
    • Select Backup from the Type drop-down box
    • Click Add file(s) and navigate to the folder where the backup file resides
    • Select the backup and click Open
  17. In the Destination pane:
    • Select Database from the Type drop-down box
    • Specify the SQL instance where the database to which to recover the data reside from the Server drop-down box
    • Specify the authentication method for that SQL instance (and a valid set of credentials if you chose SQL Server authentication)
    • Specify the name of the database you want to recover the data to in the Database drop-down box
  18. Click Compare

    Click Compare

  19. In the Main grid, select the database tables the data is to be recovered to
  20. In the Data difference pane, select the rows to be recovered
  21. Click Synchronize in the Actions region of the ribbon’s Home tab
  22. Click Next in the Synchronization direction step of the Synchronization wizard
  23. In the Output options step, of the Synchronization wizard, select Synchronize a database
  24. Click Next

    Synchronization wizard - Click Next

  25. Review the synchronization summary and warnings if any and click Finish

And that’s literally all that’s to it

April 4, 2013