1

I have a production environment running Windows Server 2000 and a development environment using SQL Server 2012. I need to make updates to the DB and implement some new features using .ASP. Is there a way to export the 2000 database and import it into 2012? All that I could find is this MS support doc about transferring the DB to 2008.

http://support.microsoft.com/kb/962355

adam2k
  • 113
  • 1
  • 1
  • 6

1 Answers1

10

Since your source server is SQL Server 2000, you can't restore directly to SQL Server 2012. You will need to restore to another instance first (2005, 2008, or 2008 R2).

On 2000:

BACKUP DATABASE dbname TO DISK = 'D:\backups\db.bak' WITH INIT;

On 2005 or 2008 or 2008 R2:

RESTORE DATABASE dbname FROM DISK = 'D:\restores\db.bak'
  WITH REPLACE, RECOVERY, MOVE (...you will likely have to specify new file locations...);

Then from there, back it up again, and then restore on the 2012 server.

Once you've restored, you'll probably want to adjust the compatibility level:

ALTER DATABASE dbname SET COMPATIBILITY_LEVEL = 110;

As well as update statistics. But note that 80 compatibility will automatically be upgraded to 90 (and you will have issues if you use syntax that is no longer supported, e.g. *= joins). While it won't catch everything, you may want to run the 2012 Upgrade Advisor while the database is in its temporary home on a 2005, 2008 or 2008 R2 instance to catch any potential issues. Also see this answer for ways the change in compatibility level may affect your existing code (the upgrade advisor won't catch many of those).

Aaron Bertrand
  • 180,303
  • 28
  • 400
  • 614
  • Thanks Aaron, I'm going to test this out this afternoon! – adam2k Jan 07 '14 at 16:21
  • I was able to backup the DB, but upon trying to restore this is the error that I received: italic The database was backed up on a server running version 8.00.0818. That version is incompatible with this server, which is running version 11.00.2100. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server. Msg 3013, Level 16, State 1, Line 1 italic – adam2k Jan 07 '14 at 19:16
  • 1
    Then your source server is 2000, not 2003 or 2005. – Aaron Bertrand Jan 07 '14 at 19:18
  • @AaronBertrand: is it possible to restore a SQL Server 2000 database in SQL Server 2012? – bjnr Jan 07 '14 at 19:22
  • 3
    @Mihai no, as I described in the answer, you need to restore it somewhere else first (2005, 2008, or 2008 R2), then backup that database, and restore that backup on 2012. – Aaron Bertrand Jan 07 '14 at 19:40
  • @AaronBertrand: the code worked in backing up the database without using WITH INIT – adam2k Jan 07 '14 at 21:21
  • @adam2k that's great, but I suggested that in case you are backing up to a filename that already exists (after all, I don't access to your hard drive), which can complicate your later efforts to restore. – Aaron Bertrand Jan 07 '14 at 21:22
  • @AaronBertrand: The only reason I didn't end up using WITH INIT is because in SQL Server 2000 it caused a syntax error. Is there some legacy SQL code that should be used there instead? Also when I go to import the data I am getting an error message about missing .mdf and .ldf files. I have both files, but they're just in a different location. Is that what the MOVE command is supposed to be used for? – adam2k Jan 07 '14 at 21:26
  • @adam2k yes, please look up the RESTORE DATABASE command for WITH MOVE syntax. I'd get you a link but I'm a bit busy at the moment. – Aaron Bertrand Jan 08 '14 at 02:01
  • @AaronBertrand - Thanks! Your answer helped resolve my issue. I needed to install SQLServer 2008 Express first to get from SQL 2000 imported too. – adam2k Jan 08 '14 at 14:28