Search results matching tags 'SQL Server 2008 R2' and 'SQL Server Denali'http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&tag=SQL+Server+2008+R2,SQL+Server+Denali&orTags=0Search results matching tags 'SQL Server 2008 R2' and 'SQL Server Denali'en-USCommunityServer 2.1 SP2 (Build: 61129.1)Downgrading a database : &quot;You can't get there from here!&quot;http://sqlblog.com/blogs/aaron_bertrand/archive/2011/01/21/downgrading-a-database-you-can-t-get-there-from-here.aspxSat, 22 Jan 2011 02:45:00 GMT21093a07-8b3d-42db-8cbf-3350fcbf5496:32831AaronBertrand<p>I see this question a lot: "I have a SQL Server 2008 R2 database.&nbsp; Can I attach it to a SQL Server 2008 SP2 instance?"</p>
<p>Part of this stems from the confusion over exactly what 2008 R2 is in the first place.&nbsp; It is not a service pack to SQL Server 2008; it is its own, full-fledged version.&nbsp; A lot of people don't fully realize this because of various reasons, including:</p>
<ul>
<li>they're on software assurance, so the upgrade to 2008 R2 was covered by their 2008 licenses, and they therefore didn't really realize it was a full version;</li>
<li>they're not running 2008 R2 in production, but they do have it in development, and didn't notice the @@VERSION change; or,</li>
<li>they're confused by the horrible naming choice.</li>
</ul>
<p>But to answer the question: No, you cannot backup/restore or detach/attach a SQL Server 2008 R2 database to any previous version, nor can you log ship or mirror in that direction.&nbsp; That is also true in going from Denali to 2008 R2/2008/2005, or from 2008 to 2005, or anything from the last 6 years to 2000 - you just can't do it.&nbsp; A lot of people expect to be able to just set the compatibility level lower, however that is not the answer.&nbsp; It is the database version and the internal file/page structures that matter here; compatibility level just tells the parser and engine how to handle certain features.</p>
<p><br><font size="4">What About Same Version, Lower Service Pack?</font> <br></p>
<p>Well, I should have known this question would come up too.&nbsp; Let's say you are building your database in SQL Server 2008 SP2 and you are ready to deploy it to production, but production is still at SP1.&nbsp; You want to get the code to production but the cycle to introduce SP2 there is far too long.&nbsp; (Now, of course, and with the understanding that hardware equivalency is
tougher, there should be a QA environment that matches production
exactly in terms of software / configuration / version.&nbsp; So it shouldn't
be going from dev to production in this manner, but I understand this
is the reality for many people.)</p>
<p>That aside, can you do it?&nbsp; Yes.&nbsp; I set out to prove this.&nbsp; In a VM I laid down three instances of SQL Server 2008: one at RTM, one at SP1, and one at SP2.&nbsp; I created two databases in SP2: SP2DB, and SP2DB_15K.&nbsp; I created one database in SP1: SP1DB. I then took backups of SP1DB and SP2DB, and tried restoring them on the RTM instance.&nbsp; This worked fine and I was able to access the databases. <br></p>
<p>On the SP2 instance, I ran the following command, to enable 15K partitions for the SP2DB_15K database:</p>
<blockquote>
<table bgcolor="#eeeeee" cellpadding="0" cellspacing="0">
<tr>
<td>
<pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"><font color="blue">EXEC</font> dbo.sp_db_increased_partitions <font color="red">'SP2DB_15K'<font color="gray">,</font> 'ON'<font color="gray">;</font></font><br><font color="blue">GO</font>
</pre></td></tr></table>
</blockquote>
<p>Then I backed up the database and tried to restore it on the RTM instance.&nbsp; I received the following error:</p>
<blockquote>
<table bgcolor="#eeeeee" cellpadding="0" cellspacing="0">
<tr>
<td>
<div style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;color:red;">Msg 3169, Level 16, State 1, Line 1<br>The database was backed up on a server running version 10.00.4000. That version is incompatible with this server, which is running version 10.00.1600. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server.<br>Msg 3013, Level 16, State 1, Line 1<br>RESTORE DATABASE is terminating abnormally.</div>
</td></tr></table>
</blockquote>
<p>If I tried to restore it on the SP1 instance, I received an almost identical error (predictably, the only thing that changes is the version string):</p>
<blockquote>
<table bgcolor="#eeeeee" cellpadding="0" cellspacing="0">
<tr>
<td>
<div style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;color:red;">Msg 3169, Level 16, State 1, Line 2<br>The database was backed up on a server running version 10.00.4000. That version is incompatible with this server, which is running version 10.00.2531. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server.<br>Msg 3013, Level 16, State 1, Line 2<br>RESTORE DATABASE is terminating abnormally.
</div>
</td></tr></table>
</blockquote>
<p>So, this exception aside, the answer is, yes, at least in SQL Server 2008, you can take a backup or detached database and restore it on an earlier service pack or RTM.&nbsp; Will this always be true?&nbsp; It's tough to say.&nbsp; Denali SP1 may introduce some change to the internal structure or database version, optional or otherwise, that will prevent it from being restored on RTM, just like our exception above.<br></p>
<p><br><font size="4">Going Forward Always Works, Right?</font> <br></p>
<p>As for the other direction, it is usually fine to backup/restore, detach/attach, log ship or mirror from an older version to a newer version; however, there are exceptions.&nbsp; For example, Denali does not support the 80 compatibility level, so restoring or attaching a SQL Server 2000 database on a Denali instance is out of the question (I <a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/18/sql-server-v-next-denali-restoring-a-sql-server-2000-database.aspx" title="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/18/sql-server-v-next-denali-restoring-a-sql-server-2000-database.aspx" target="_blank">blogged about this here in November</a>).&nbsp; Another example is with SQL Server 2008 SP2 - if you have enabled support for 15,000 partitions, the internal database version is upgraded to 662, and you cannot then migrate to SQL Server 2008 R2 because R2 does not understand that version (it is expecting 661) - in this case you will have to wait until 2008 R2 SP1, when support for 15K partitions is added and the database versions will once again have an upgrade path.&nbsp; Here is what happens when I try to restore the SP2DB_15K database on an R2 instance:</p>
<blockquote>
<table bgcolor="#eeeeee" cellpadding="0" cellspacing="0">
<tr>
<td>
<div style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;color:red;">Msg 3169, Level 16, State 1, Line 1<br>The database was backed up on a server running version 10.00.4000. That version is incompatible with this server, which is running version 10.50.1746. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server.<br>Msg 3013, Level 16, State 1, Line 1<br>RESTORE DATABASE is terminating abnormally.
</div>
</td></tr></table>
</blockquote>
<p>(Note that this doesn't happen with the SP2DB database, which did not have 15K partitions enabled.) <br></p>
<p>It does work on Denali, however; here is what happens when I restore the SP2DB_15K database on a Denali CTP1 instance:</p>
<blockquote>
<table bgcolor="#eeeeee" cellpadding="0" cellspacing="0">
<tr>
<td>
<div style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;">Processed 160 pages for database 'SP2DB_15K', file 'SP2DB_15K' on file 1.<br>Processed 2 pages for database 'SP2DB_15K', file 'SP2DB_15K_log' on file 1.<br>Converting database 'SP2DB_15K' from version 662 to the current version 684.<br>Database 'SP2DB_15K' running the upgrade step from version 662 to version 668.<br>Database 'SP2DB_15K' running the upgrade step from version 668 to version 669.<br>Database 'SP2DB_15K' running the upgrade step from version 669 to version 670.<br>Database 'SP2DB_15K' running the upgrade step from version 670 to version 671.<br>Database 'SP2DB_15K' running the upgrade step from version 671 to version 672.<br>Database 'SP2DB_15K' running the upgrade step from version 672 to version 673.<br>Database 'SP2DB_15K' running the upgrade step from version 673 to version 674.<br>Database 'SP2DB_15K' running the upgrade step from version 674 to version 675.<br>Database 'SP2DB_15K' running the upgrade step from version 675 to version 676.<br>Database 'SP2DB_15K' running the upgrade step from version 676 to version 677.<br>Database 'SP2DB_15K' running the upgrade step from version 677 to version 678.<br>Database 'SP2DB_15K' running the upgrade step from version 678 to version 679.<br>Database 'SP2DB_15K' running the upgrade step from version 679 to version 680.<br>Database 'SP2DB_15K' running the upgrade step from version 680 to version 681.<br>Database 'SP2DB_15K' running the upgrade step from version 681 to version 682.<br>Database 'SP2DB_15K' running the upgrade step from version 682 to version 683.<br>Database 'SP2DB_15K' running the upgrade step from version 683 to version 684.<br>RESTORE DATABASE successfully processed 162 pages in 0.021 seconds (60.174 MB/sec).
</div>
</td></tr></table>
</blockquote> <p>And the messaging is similar for the other databases from the 2008 instance, except their version starts at 661 instead of 662.<br></p><p><br><font size="4">But I'm Still Stuck!<br></font></p>
<p>So, you have a database that has been upgraded to 2008 R2 and you need to get it back onto 2008 or 2005?&nbsp; There is no straight path for this scenario; it's kind of like <a href="http://www.cartogrammar.com/blog/you-cant-get-there-from-here/" title="http://www.cartogrammar.com/blog/you-cant-get-there-from-here/" target="_blank">driving in Boston</a>.&nbsp; Assuming you aren't using any features that are exclusive to the newer version (and that you can suspend activity against the newer database temporarily), you can use a schema comparison tool like <a href="http://www.red-gate.com/products/sql-development/sql-compare/" title="http://www.red-gate.com/products/sql-development/sql-compare/" target="_blank">Red Gate's SQL Compare</a>, to build the modules and schema in an empty database on the older version, then use <a href="http://msdn.microsoft.com/en-us/library/bb522535.aspx" title="http://msdn.microsoft.com/en-us/library/bb522535.aspx" target="_blank">Integration Services</a> to migrate the data.&nbsp; </p><p>&nbsp;</p>