How to restore a higher version SQL Server database backup file onto a lower version SQL Server?
Using SQL Server 2008 R2 (10.50.1600), I made a backup file and now I want to restore it on my live server's SQL Server 2008 (10.00.1600).
When I tried to restore the backup onto SQL Server 2008 it gives an error i.e. Restore Failed because:
The database was backed up on a server running version 10.50.1600.
That version is incompatible with this server, which is running version
10.00.1600.
How do I restore the backup file on this server?
You can use functionality called Export Data-Tier Application which generates .bacpac file consisting database schema and data.
On destination server, you can use Import Data-Tier Application option which creates and populates new database from pre-created .bacpac file
If you want just to transfer database schema, you can use Extract Data-Tier Application for creating file and Deploy Data-Tier Application for deploying created database schema.
I've tried this process on different versions of SQL Server from SQL 2014 to SQL 2012 and from SQL 2014 to SQL 2008R2 and worked well.
No, is not possible to downgrade a database. 10.50.1600 is the SQL Server 2008 R2 version. There is absolutely no way you can restore or attach this database to the SQL Server 2008 instance you are trying to restore on (10.00.1600 is SQL Server 2008). Your only options are:
upgrade this instance to SQL Server 2008 R2 or
restore the backup you have on a SQL Server 2008 R2 instance, export all the data and import it on a SQL Server 2008 database.
You can not restore database (or attach) created in the upper version into lower version. The only way is to create a script for all objects and use the script to generate database.
select "Schema and Data" - if you want to Take both the
things in to the Backup script file select Schema Only -
if only schema is needed.
Yes, now you have done with the Create Script with Schema and Data of the Database.
Will not necessarily work
Backup / Restore - will not work when the target is an earlier MS SQL version.
Copy Database - will not work when the target is SQL Server Express: "The destination server cannot be a SQL Server 2005 or later Express instance."
Data import - Will not copy the schema.
Will work
Script generation - Tasks -> Generate Scripts. Make sure you set the desired target SQL Server version on the Set Scripting Options -> Advanced page. You can also choose there whether to copy schema, data, or both. Note that in the generated script, you may need to change the DATA folder for the mdf/ldf files if moving from non-express to express or vice versa.
Microsoft SQL Server Database Publishing Services - comes with SQL Server 2005 and above, I think. Download the latest version from here. Prerequisites: sqlncli.msi/sqlncli_x64.msi/sqlncli_ia64.msi, SQLServer2005_XMO.msi/SQLServer2005_XMO_x64.msi/SQLServer2005_XMO_ia64.msi (download here).
Here are my 2 cents on different options for completing this:
Third party tools: Probably the easiest way to get the job done is to create an empty database on lower version and then use third party tools to read the backup and synchronize new newly created database with the backup.
Red gate is one of the most popular but there are many others like ApexSQL Diff , ApexSQL Data Diff, Adept SQL, Idera …. All of these are premium tools but you can get the job done in trial mode ;)
Generating scripts: as others already mentioned you can always script structure and data using SSMS but you need to take into consideration the order of execution. By default object scripts are not ordered correctly and you’ll have to take care of the dependencies. This may be an issue if database is big and has a lot of objects.
Import and export wizard: This is not an ideal solution as it will not restore all objects but only data tables but you can consider it for quick and dirty fixes when it’s needed.
Another way to do this is to use "Copy Database" feature:
Find by right clicking the source database > "Tasks" > "Copy Database".
You can copy the database to a lower version of SQL Server Instance. This worked for me from a SQL Server 2008 R2 (SP1) - 10.50.2789.0 to Microsoft SQL Server 2008 (SP2) - 10.0.3798.0
You can try this.
Create a Database onto SQL Server 2008.
Using Import Data feature import data from SQL Server R2 (or any higher version).
use "RedGate SQLCompare" to synchronize script.
Go to Task->Generate Scripts...
In Advanced in "Types of data for script" select "Schema and data" and try to run this script in your lower version.
It's not pretty, but this is how I did it granted you have this option installed on your SQL 2008 R2 install..
1) Right click database in SQL Server 2008 R2 "Tasks".. "Generate scripts" in the wizard, select the entire database and objects in first step. On the "Set Scripting Options" step you should see a button "Advanced" , select this and make sure you select "Script for Server Version" = SQL Server 2008" not R2 version.
This is a crucial step, because "import data" by itself does not bring along all the primary keys, constriants and any other objects like stored procedures."
2) Run the SQL script generated on the new install or database instance SQL Express or SQL Server 2008 using the query window or open saved .sql script and execute and you should see the new database.
3) Now right click on the new database and select "Tasks".. "Import Data.." choose source as the R2 database and the destination as the new database. "Copy data from one or more tables or views", select the top checkbox to select all tables and then next step, run the package and you should have everything on a older version. This should work for going back to a 2005 version as well. Hope this helps someone out.
you can use BCP in and out for small tables.
BCP OUT command:-
BCP "SELECT * FROM [Dinesh].[dbo].[Invoices]" QUERYOUT C:\av\Invoices1.txt -S MC0XENTC -T -c -r c:\error.csv
BCP IN command:-
Create table structure for Invoicescopy1.
BCP [Dinesh].[dbo].[Invoicescopy1] IN C:\av\Invoices.txt -S MC0XENTC -T -c
I appreciate this is an old post, but it may be useful for people to know that the Azure Migration Wizard (available on Codeplex - can't link to is as Codeplex is at the moment I'm typing this) will do this easily.
You'd have to use the Import/Export wizards in SSMS to migrate everything
There is no "downgrade" possible using backup/restore or detach/attach. Therefore what you have to do is:
Backup the database from the server running the new SSMS/SQL version.
Import data from the generated .bak file, by expanding the "Tasks" menu(after right-clicking the target database) and selecting the "Import Data" option.
You can generate script from Task menu
For detailed reference
How to migrate a SQL Server database to a lower version
Related
I can't attach my database. When I try to attach a database in SQL Server Management Studio, I get this error:
The database 'C:\FILES\ACCOUNTING.MDF' cannot be opened because it is version 904. This server supports version 852 and earlier. A downgrade path is not supported. Could not open new database 'C:\FILES\ACCOUNTING.MDF'. CREATE DATABASE is aborted. (.Net SqlClient Data Provider)
and I have tried these commands:
cd "C:\Program Files\Microsoft SQL Server\130\LocalDB\Binn"
SqlLocalDB.exe delete "MSSQLLocalDB"
SqlLocalDB.exe create "MSSQLLocalDB"
but it still has an error
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server (v904 = SQL Server 2019) down to an older version (v852 which is SQL Server 2016) - the internal file structures are just too different to support backwards compatibility.
You can either get around this problem by
using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances
otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (Tasks > Generate Scripts) or using a third-party tool
or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.
The error message in the problem statement occurs because the SQL Server database files (*.mdf, *.ndf and *.ldf) and backups are not backward compatible. Backward compatibility is why we cannot restore or attach a database created from a higher version of SQL Server to a lower version of SQL Server. However, there are a few options that can help us to downgrade the database from a higher version of SQL Server to a lower version SQL Server. These options include:
Use the Generate Scripts Wizard in SQL Server Management Studio
Use SQL Server Integration Services
Create Custom Scripting and BCP
In this tip we will use the Generate Scripts Wizard in SQL Server Management Studio.
Here are the basic steps we need to follow:
Script the database schema and data from the higher version of SQL Server by using the Generate Scripts Wizard in SSMS.
Connect to the lower version of SQL Server, and run the SQL scripts that were generated in the previous step, to create the database schema and data.
In the next section, I will demonstrate the steps for downgrading a SQL Server 2012 database to SQL Server 2008 R2 database.
Steps to Downgrade a SQL Server Database Using SSMS Generate Scripts Wizard
Step 1 Script the schema of the OUTLANDER database on the SQL Server
2012 instance (IITCUK\DEV01) using the Generate Scripts wizard in
SSMS.
In Object Explorer connect to IITCUK\DEV01, right-click on the
OUTLANDER database, expand Tasks and choose "Generate Scripts...".
This launches Generate and Publish Scripts wizard. Click Next, to skip the Introduction screen and proceed to the Choose Objects page.
On the Choose Objects page, choose option "Script entire database and all database objects", and then click Next to proceed to "Set Scripting Options" page.
n the Advanced Scripting Options dialog box,
set Script for Server Version to SQL Server 2008 R2 (or whatever version you want)
under the Table/View Options, set Script Triggers, Script Indexes and Script Primary Keys to True
and set Types of data to script to Schema and Data - this last option is key because this is what generates the data per table.
Once done, click OK, to close the Advanced Scripting Options dialog box and return to Set Scripting Options page. In Set Scripting Options page, click Next to continue to Summary page.
After reviewing your selections on Summary page, click Next to generate scripts.
Once scripts are generated successfully, choose the Finish button to close the Generate and Publish Scripts wizard.
Step 2 Connect to the SQL Server 2008 R2 instance
(IITCUK\SQLSERVER2008), and then run the SQL scripts that were
generated in Step 1, to create the OUTLANDER database schema and data.
In Object Explorer connect to IITCUK\SQLServer2008, then in SQL Server
Management Studio, open the SQL Server script you saved in Step 1
Modify the script, to specify the correct location for the OUTLANDER database data and log files. Once done, run the script to create the OUTLANDER database on IITCUK\SQLServer2008 instance.
Upon successful execution, refresh the Database folder in Object Explorer. As you can see in the following image, the OUTLANDER database has been successfully downgraded.
Notes
There are a few things to be aware of when using this approach.
This solution creates one large SQL file that has the scripts to create the database objects and also INSERT statements for the data in the tables.
For a large databases, the SQL file can get very large if you script out both the schema and the data and could be hard to load into an editor. Also, you may get a memory related error message from the editor if the file is too big.
For large databases, around 1GB or more, if this approach does not work, then you should look at using SSIS to migrate the database or create custom scripts to script out the objects and BCP out the data for each of the tables. You can use this Generate Scripts wizard to just generate the schema without the data and use SSIS or BCP to export and import the data.
This approach works for SQL Server 2017 to SQL Server 2005. Some of the scripting options might be a bit different in newer versions, but the process is still the same.
Before just executing the script, you should review the script to make sure everything looks correct such as the path of the database files, database options, etc.
Also if you are using new functionality that does not exist in the lower version, SQL Server won't be able to create the objects and you will need to review the scripts that were generated and update the code accordingly.
For a very simple database this approach should work pretty easliy, but you might need to spend some time making some modifications to the script for a more complex database.
Below is a list of all of the scripting options. If you click on an item, the bottom part of the screen gives you a short definition of the option.
Next Steps
To avoid this issue, always make sure that you perform a full backup of the database before you upgrade the SQL Server and database to a higher version of SQL Server. In addition, be sure to thoroughly test the application prior to releasing the application to the users.
Consider this downgrade option as your last option to rollback from an upgrade because the time and storage needed can be very large.
With a very large database be sure you have sufficient storage to support the data needs.
Be sure to verify row and object counts as well as test your application before releasing to production.
Additional Resources:
Why Can't I Restore a Database to an Older Version of SQL Server?
SQL Server Database Engine Backward Compatibility
SQL Server Upgrade Tips
I used visual studio 2013 for developing a web application and used a localDB in development phase, now I want to go to production phase and want to export the sql server localDb to the online SQL server database, but I cannot find any option to script out the localDb or migrate it?
Which tools I can use to do this ? or what I must do?
There are atleast two routes; you could publish and recover as Data Tier Application:
Or, the easier-but-lengthier route would be to:
Create a new DB in the SQL Server Management Studio (Naming it the same as LocalDB is helpful if you just want to change the connection string later)
Right-click database on SQL Server Object Explorer and select Schema Compare
Click Select Target and navigate through Select Target Schema(Dialog) > Database > Click on Select Connection > Connect(Dialog) > Browse > Local > Database Name > Select the Databse you created in Step-1. Then, click OK
Click Compare or, hit Shift+Alt+C
Then, the Schema Comparator tells you whats different between the two databases (the one from MSSqlLocalDB and the one you just created in Step-1). It is important to remember unchecking ANY entries for delete operations, if you are simply transferring data and schema. Keep add operations as it is.
Then, click on ↑UPDATE (the option is located right beside Compare)
Your Target database should be updated
You can attach the localDb to SQLServer 2005 or higher and then you can generate scripts or export data to remote server.
Or
If LocalDb is SQL Server 2012, use SSMS 2012 or later for this scripting task.
Unfortunately VS2013 does not has any feature to script out a localDb, I waste so many time to copy table by table scripts, and run it at remote db. my local db id sql v11.0 (2012 I think). and the remote db was sql server 2008. so one way exist is to install an instance of sql server 2012 and sql server management studio to script out my db. maybe another tools also exist it is very sad that vs has not this feature.
Were there any changes in this area with SQL Server 2014? I’ve seen this post Is it possible to restore Sql Server 2008 backup in sql server 2005 and I know that this was not possible as a scenario for 2012 -> 2008 but I wonder if MS made any changes here with the 2014 version.
We are evaluating 2014 version and we have a fairly large database in testing. We’d like to restore a backup of that database to SQL Server 2008 because that physical machine has more space, RAM,…
I’m getting standard error message when I try to restore backup but I was wondering if there is something else in SQL Server 2014 that I might be missing.
No, it is not possible. Stack Overflow wants me to answer with a longer answer, so I will say no again.
Documentation: https://learn.microsoft.com/en-us/sql/t-sql/statements/backup-transact-sql#compatibility
Backups that are created by more recent version of SQL Server cannot
be restored in earlier versions of SQL Server.
Not really as far as I know but here are couple things you can try.
Third party tools: Create empty database on 2008 instance and use third party tools such as ApexSQL Diff and Data Diff to synchronize schema and tables.
Just use these (or any other on the market such as Red Gate, Idera, Dev Art, there are many similar) in trial mode to get the job done.
Generate scripts: Go to Tasks -> Generate Scripts, select option to script the data too and execute it on 2008 instance. Works just fine but note that script order is something you must be careful about. By default scripts are not ordered to take dependencies into account.
It is a pretty old post, but I just had to do it today. I just right-clicked database from SQL2014 and selected Export Data option and that helped me to move data to SQL2012.
Pretty old question... but I had the same problem today and solved with script, a little bit slow and complex but worked. I did this:
Let's start from the source DB (SQL 2014) right click on the database you would like to backup -> Generate Scripts -> "Script entire database and all database objet" (or u can select only some table if u want) -> the most important step is in the "Set Scripting Options" tab, here you have to click on "Advanced" and look for the option "Script for Server version" and in my case I could select everything from SQL 2005, also pay attention to the option "Types of data to script" I advice "Schema and data" and also Script Triggers and Script Full-text Indexes (if you need, it's false by default) and finally click ok and next. Should look like this:
Now transfer your generated script into your SQL 2008, open it and last Important Step:
You must change mdf and ldf location!!
That's all folks, happy F5!! :D
No I guess you cannot restore the databases from higher version to lower version , you can make data flow b/w them i,e you can scriptout.
http://www.mssqltips.com/sqlservertip/2810/how-to-migrate-a-sql-server-database-to-a-lower-version/
Please use SQL Server Data Tools from SQL Server Integration Services (Transfer Database Task) as here: https://stackoverflow.com/a/27777823/2127493
If you have both versions you can create a merge replication from new to old. Create a merge publication on your newer sql server and a subscription on the older version. After initializing the subscription you can create a backup of the database with the same structure and the same content but in an older version and restore it on your old target server.
You can use this method also with sql server 2016 to target 2014, 2012 or 2008.
I have a database deployed on a testing machine and a production machine. There is some data (columns of a table) in the testing database that I would like to copy over to production.
When I try to restore a backup onto the production box I get the following error:
System.Data.SqlClient.SqlError: The database was backed up on a server running version 10.50.1600. That version is incompatible with this server, which is running version 10.00.4000. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server. (Microsoft.SqlServer.Smo)
Is there an alternate way to get the data into the table?
This answer ONLY if you need the data (from here: http://sqlserverlearner.com/tag/the-database-was-backed-up-on-a-server-running-version-10-50-1600-that-version-is-incompatible-with-this-server):
Script the object you want (table and data) under tasks, generate scripts, select the object, and make sure to include all the data (possibly the schema as well). Take this to a new query window and save the SQL file, then execute it on your other server.
You could
Generate INSERT statements for the data in question
Create a linked server from the test to the other server and run sql statements against that
Upgrade the target server to 2008 R2 (this is not something to take lightly)
You should keep your environments at the same version / rev. SQL Server restores are not backward compatible.
Use generate scripts with data, you can select the version of MSSQL. Then run the outputted SQL on the server you want it.
Ideally you'd upgrade your production server to match your test environment, otherwise your tests may not always be representative.
If they are different versions though, you can't restore a database to an older version of SQL server, you should either use the generate scripts command to create the new table and insert the data, or use a tool like SQL compare/Data Compare from RedGate which will do all of this for you.
This is the problem with the sqlserver version mismatch while restoring the database. It means It couldn't possible to restore the database server 2008 to 2005. It wouldn't support higher version to lowerr version.
The following options are available,
You can link the servers and move the table from one server to other server
Generate the sql script and execute in the target database
Use the below URL to generate the insert script and execute generated script into target server.
http://www.codeproject.com/Articles/5598/Generating-INSERT-statements-in-SQL-Server
you can use redgate toolbelt tool kit to sync data between different version of sql server or sql server to sql azure or sql azure to sql server database . it is very very easy to use .
I installed VS 11 beta and SQL Server 2012 on my development machine and at one point, I was asked to upgrade my database from version 661 (SQL Server 2008 R2) to SQL Server 2012.
I clicked yes, continued building, and now I've just realized that the file won't deploy in SQL Server 2008 R2, which is the version installed on the staging server (I don't control that machine).
I've thought of exporting the database to another format (access for instance) and reimporting it in SQL Server 2008 R2. Is that the best way to solve my problem? Is there another better way?
Thanks for your suggestions.
You have at least four options:
Restore your last pre-upgrade backup
Re-create the database from scripts in source control
Use SMO to generate scripts for all objects and re-create the database
Use SSIS or a third-party tool to copy all database objects from one DB to another
If you opt to re-create the database from scripts, you can then use SSIS or bcp to copy the data over. But restoring a backup is by far the easiest solution and if you don't take regular backups of your development environment then this might be a good time to start.
And as someone else advised, do not develop using tools and versions that don't match your production environment.
Look at this 10-minute solution to learn how to recreate your upgraded database using "Generate SQL Server Scripts" wizard.