10
votes

If I create a database using 2012 and work and add that info to it, if I were to script the database after, would I be able to run the script in 2008 and have everything work A.O.K?

3
It would probably be safer to start in 2008 and migrate to 2012.John Dewey
Only reason I ask is that I have a Windows Server 8 Beta installation with SQL Server 2012 and want to setup access to SQL externally so I can work on a project from my classroom. This way my project partner and I will both have the latest database to work with rather than having to pass back and forth a copy of the database and trying to merge it together all the time with each of our changes. In the end, the database must be able to attach to a 2008 version though. And I'd rather not uninstall/reinstall 2008 to do this.Shane LeBlanc

3 Answers

22
votes

If you are using SQL Management Studio, you can right-click on the database name, then select Tasks → Generate Scripts.

Here you will be able to create scripts to script out the Schema, Data, or both Schema and Data, and if you click the Advanced button, you can specify which version of SQL Server you'd like to target.

So, simply choose SQL 2008 as the destination server and you should be good to go!

10
votes

A script? Yes. Well, let me rephrase: it depends. As long as your objects don't use any 2012-specific features, you will be able to script out the schema using Management Studio or a variety of 3rd party tools (I blogged about some options here). Many of the tools also offer options (or companion tools) to also script the data.

The problem is there isn't a very easy way in SQL Server 2012 to identify all of the places where you might be using 2012-specific features. For example, I don't know of a tool that will inspect your database and point out that you are using the FORMAT() function, which is not available in SQL Server 2008 or 2008 R2.

Other means of copying the database over - backup/restore, attach/detach, mirroring/log shipping etc. will not work. You can go up (from 2005, 2008 or 2008 R2) to 2012, but you can't go backwards.

So in general I agree with John. Much safer to develop on a version <= deployment version. Why would you want to develop on 2012 to deploy to 2008? Seems quite risky to me.

2
votes

If you have very large amounts of data to move (gigabytes) then the TSQL scripts that the SQL Management Studio will generate for you could give you problems because of the sheer size. A better alternative would be to use BCP (Bulk Copy Program). The downside is that this is a command line utility and requires more work than just using the wizard.

As luck would have it somebody has written something which looks remarkably like the wizard only using BCP. It is the SQL Database Migration Wizard and is freely available on Codeplex - http://sqlazuremw.codeplex.com/releases/view/32334. Originally intended as a database migration tool between SQL Server and Azure you can just as easily use it between SQL Server and SQL Server. The key is to go into the advanced options (similar to the Management Studio wizard) and pick SQL Server. Later when you are prompted for the target system choose your 2008 installation.

I had no 2012 specific artefacts in my database and it worked very smoothly for me.