I had a discussion earlier today (with Paul Randal) about many misconceptions that exist about upgrading databases and more importantly, about “downgrading” databases. Really, the issue is that I’ve heard people get frustrated when they find that things like backup/restore works FROM SQL 7.0/2000 TO SQL Server 2005 but not the other way around – even if the database is in SQL Server 2000 (80) compatibility mode. First and foremost, compatibility mode only affects parsing, query processing, and general data manipulation; it does not affect physical storage (well, there’s more to it than that but that’s a general overview). When you upgrade a database to SQL Server 2005, you WILL benefit immediately from changes in the storage engine, etc. regardless of compatibility mode. Compatibility modes are there to give you time in updating/upgrading your code – if/when necessary. Most code will work when upgrading but some code may not be supported because of changes to keywords, syntax changes, etc… The best thing to do is check your application compatibility with the Upgrade Advisor. I did a a couple of webcasts on Installation/Upgrade as part of my 11-part series on TechNet. See the blog entry for the entire series here. Part 3 and part 4 are focused on Installation and Upgrade and their associated blog entries have a lot of additional links (including links to the Upgrade Advisor as well as a series of things you might want to do before you upgrade). Also, be sure to checkout the upgrade site off of the main Microsoft SQL Server site.


How to move USER databases around – a quick list of what’s supported between versions



Backup/Restore from 7.0 to SQL Server 2000
Detach from 7.0, copy the files, then attach to SQL Server 2000
Backup/Restore from 7.0 to SQL Server 2005
Detach from 7.0, copy the files, then attach to SQL Server 2005
Backup/Restore from 2000 to SQL Server 2005
Detach from 2000, copy the files, then attach to SQL Server 2005


Why use Backup/Restore?


PROs



  1. Because you have a backup! This will allow you to go back to the version from which you came. However, without any changes made on the uplevel version.

  2. Because it doesn’t require the database to be taken “offline” when the backup is performed (note: that this is both good and bad – bad because you don’t really know the exact point in time to which the database reconciles…which may not matter if you’re just testing).

  3. Because the backup will be the size of data only and will not include database free space. Free space is not backed up (e.g. a database with a 100GB data file with only 20GB of data should yield a file that’s roughly 20GB in size). I say “roughly 20 GB” because the internals of a backup require that the transaction log records for the activity that occured during the backup process are also backed up with the full database (or differential) backup. This is actually the basis for why transaction log backups are not supported during a full/differential backup in SQL Server 2000 (they are in SQL Server 2005). However, this is the reason why the transaction log cannot be cleared while a full or differential is ALSO running in SQL Server 2005.

CONs



  1. You don’t know the exact point in time to which the database reconciles (it will be the time that the backup completed) AND logs CAN be restored uplevel as well. NOTE: If you’re interested in creating an exact point in time version of the database – consider putting the database into “restricted user” mode or “single user” mode (so that user transactions are not allowed during the backup). Again, this may not be a concern.

  2. It takes time to complete the backup (there are four phases of a restore: create/initialization, copy, redo, undo). Make the create/initialization *much* faster by enabling Instant Initialization. See my Instant Initialization blog post for more details.

Why use detach/attach?


PROs



  1. It’s simple, it’s fast… but once detached then the database is OFFLINE.

  2. You know the exact point in time to which it reconciles because no transactions are allowed into the database once it is offline. Again, this may not be a concern.

CONs



  1. You must copy the entire file – including the free space to the other location and the network copy might be the most expensive (meaning time consuming) part of the entire process. However, once copied, the files do NOT need to be created on the destination because on attach, these files will be used.

  2. The database is offline once detached and during copy.

  3. If you don’t COPY the files and instead you attach the detached files, you will have ABSOLUTELY NO WAY of getting back to the version from which you detached. (ah, this is probably the single most important reason for why I prefer backup/restore!)

Summary for “How to move USER databases around”
Between these versions “upgrades” are supported ONLY to the uplevel version. There is NO single (or simple) feature that can be used to get back to the version from which you started (without exporting/importing all of the data). There is also no undocumented back-door to do this either (no trace flags, no DBCC commands, NA DA!!! as per Paul).


What about System Databases?
This is a whole other can of worms to open and the easiest thing I can say here is that you generally should not move/upgrade system databases across machines. These are upgraded through “in-place” upgrades of SQL Server (on the same machine) or through manual migrations (to different machines) of the users/objects (SQL Agent Jobs, user-defined system procedures in master, logins in master, etc.). This is not an easy process (manual migration) but may prove to be a better choice over an upgrade in place if something were to go horribly wrong (which is unlikely but I’m a “what’s the worst case scenario” person when it comes to availability :). The other benefit of NOT upgrading in place – and instead MOVING databases from one version to another on an upgrade – is that you get to complete some basic “spring cleaning”. New hardware, freshly formatted, freshly installed/configured OS, clean disks, etc. This can often alleviate some of the strangest, hard-to-determine-problems, that have plagued you for weeks/months. Like I said, this is a whole other can of worms to open!


But – if you’re interested in moving system databases around on the SAME machine, here’s a great KB that covers the required options, syntax, rules and restrictions: How to move SQL Server databases to a new location by using Detach and Attach functions in SQL Server


And – if you’re interested in transferring logins and passwords between instances (for upgrade or for sync’ing two servers used to create a standby partnership – with Database Mirroring and/or Log Shipping), here’s a great KB article that includes links to other articles even uplevel transfering of logins (like 2000 to 2005): How to transfer logins and passwords between instances of SQL Server


And – that’s it for this week (probably)… two in a row is not likely to become three in a row (just setting expectations :) :) :),
kt