Convert SQL Server 2008 database to SQL Server 2005 - sql-server

Convert SQL Server 2008 database to SQL Server 2005. Any solution please?

You can script your 2008 database to create the database objects and insert data, then run that script on the 2005 instance. You might have to temporarily disable foreign keys to get some of the inserts to work.

If you want to set the compatibility level of your 2008 SQL Servers to be 2005 (so that you are effectively saying that they are all 2005), you can use the SET COMPATIBILITY_LEVEL command to do this...MSDN link
Using there example, you would run this on your 2008 databases:
ALTER DATABASE database_name -- change me!
SET COMPATIBILITY_LEVEL = 90 -- set to sql server 2005 compatibility level

Related

Is it safe to do forward restore in SQL Server?

I have restored a .bak file from my SQL Server 2008 R2 to my 2017 instance (both Developer editions) and it seems to work fine.
Does it really restore all the user defined objects? And are all those objects work same as the way they work in 2008 R2 instance?
Yes, SQL Server 2017 has a forward compatibility with backups created in SQL Server 2008R2.
The restore process restores all user and system objects and then perform an upgrade of them to a current version.
Important: the database will still be in an old compatibility level - 100, which corresponds to SQL Server 2008R2. In order to get all new optimizations and features available, consider to change your database to the latest compatibility level. For SQL Server 2017 it is: 140.
ALTER DATABASE [DbName] SET COMPATIBILITY_LEVEL = 140;
This will also enable query optimizer and t-sql enhancements which were introduced since 2008R2.
And then update statistics
USE [DbName]
EXEC SP_UPDATESTATS
Worth to mention that compatibility change is a backward reversal, while backup created in SQL Server 2017 cannot be restored in 2008R2.
yes, they will work fine in 2008 R2 Instance.

Backup and Restore SQL Server database from higher version to lower version

I'm looking for a way to create a command line script to backup SQL Server 2016 which can be restored in a older version SQL Server 2012.
We have a daily backup from our SQL Server 2016 using the
BACKUP DATABASE XXXX TO DISK = "C:\BACKUP.BAK"
and this back up is provided to a 3rd party which is running an older SQL Server 2012.
When they use SMSS they get an error stating an error about the incompatible version.
I've tried using ALTER DATBASE XXXX SET COMPATIBILITY_LEVEL = 110 ( targeting even a lower than SQL Server 2012 version)... thinking it can be loaded in their 2012 but when they try to load it, it still states that the backup file is in 2016 (v13.xxx) ?!
Sample backup script
USE MYDB;
ALTER DATABASE MYDB SET SINGLE_USER
GO
-- TARGETING SQL Server SQL Server 2012
ALTER DATABASE MYDB SET COMPATIBILITY_LEVEL = 110
GO
BACKUP DATABASE MYDB
TO DISK = 'C:\TEMP\MYDB.BAK'
ALTER DATABASE MYDB SET MULTI_USER
GO
Can anyone let me know what Im doing wrong?
Thanks
You just simply CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server down to an older version - the internal file structures are just too different to support backwards compatibility. And the "database compatibility level" also doesn't help.
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.

Parse SQL script as 2005 in 2012?

In SQL Server 2012 Management Studio, is there a way to to parse my SQL as SQL Server 2005 syntax? My development PC has SQL Server 2012 Express but the production server uses 2005. I have to hook into a 2005 development server to run my tests before pushing to production.
It would be really nice if I could test for SQL Server 2005 correctness from a 2012 server
use Compatibility Level.
For 2005, use COMPATIBILITY_LEVEL 90
ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL = 90
refer to here for more information
https://msdn.microsoft.com/en-us/library/bb510680.aspx

Can we restore SQL Server 2008R2 backup on SQL Server 2014?

Currently, one of our product running on the SQL Server 2008R2.
For new installation client want to go for SQL Serer 2014 because at this location Microsoft is not selling licence for the SQL Server 2008R2.
In SQL Server 2014, you can restore a user database from a database backup that was created by using SQL Server 2005 or a later version. However, backups of master, model and msdb that were created by using SQL Server 2005 through SQL Server 2012 cannot be restored by SQL Server 2014. Also, backups created in SQL Server 2014 cannot be restored by any earlier version of SQL Server.
Source
Yes.
Wen you restore database backup that created with older version of SQL Server in to new version, SQL Server automatically updated your database in new version. But don't change compatibility level of your database. You can change Compatibility level of your database after restore complete by following query :
ALTER DATABASE test SET COMPATIBILITY_LEVEL = 120
In SQL Server 2014 SP1 there are breaking changes to the restoreheader definition (3 new fields added).
If you use it, you should have a look at this thread:
breaking changes to SQL Server 2014 SP1 - restoreheader

Compatibility level for SQL Server database

My database hoster allows to restore SQL Server databases with a compatibility level of 90 (SQL Server 2005). My database is created locally with a compatibility level of 100 (SQL Server 2008).
So, I generated script of my database (version 2008) and run in SQL Server 2005, backup and restore to my database hoster, it works. Currently I do likes it.
And then I found ALTER DATABASE that can change compatibility level of database likes
ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL = { 90 | 100 | 110 }
90 = SQL Server 2005
100 = SQL Server 2008 and SQL Server 2008 R2
110 = SQL Server 2012
I turn my database compatibility level using this script in SQL Server 2008, backup my database and restore to my database hoster. But it doesn't work. I want to know why? Is there a better way to fix it ?
You can NEVER restore a database from a newer version of SQL Server (like your 2008 version) onto an older SQL Server (2005) instance.
No matter what you try, no trick, no hack, no workaround - it just cannot be done.
The compatibility level doesn't make any difference either. It just makes your newer database (like on 2008) behave as if it were an older one (like 2005) - so the features you can use are limited to what the older database supported.
But internally - it's still a 2008 database and it cannot be restored to a 2005 instance.
You can't go back to version compatibility of sql server better to go through scripts.
Make a new database
Import the tables in the new database
Then generate the script of procedures and functions and run this script on the new database

Resources