<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by Fredrik Söderberg</title><link href="http://world.optimizely.com" /><updated>2010-12-21T11:31:00.0000000Z</updated><id>https://world.optimizely.com/blogs/Fredrik-Soderberg/</id> <generator uri="http://world.optimizely.com" version="2.0">Optimizely World</generator> <entry><title>SQL backward compatibility issues</title><link href="https://world.optimizely.com/blogs/Fredrik-Soderberg/Dates/2010/12/SQL-backward-compatibility-issues/" /><id>&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Compatibility&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Have you ever had backward&amp;nbsp;compatibility issues with different SQL Server database versions?&amp;nbsp;I.e. you can&#39;t use a database from a newer&amp;nbsp;SQL version in an older or you&#39;re not able to restore a backup from a newer SQL version to an older.&amp;nbsp;An example of an&amp;nbsp;error message you get&amp;nbsp;when trying to use a database from SQL Server&amp;nbsp;2008 R2&amp;nbsp;in 2008:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&quot;The database &quot;dbDemo&quot; cannot be opened because it is version 661. The server supports version 655 and earlier.&quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A solution is to upgrade the database.&amp;nbsp;If&amp;nbsp;that isn&#39;t an option,&amp;nbsp;then what to do?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Try&amp;nbsp;Scripting!&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;Scripting a database&amp;nbsp;is just another way of taking a copy/backup of&amp;nbsp;a whole or part of a database. The outcome is a sql-script which is&amp;nbsp;backward compatible. I.e. if you script a database you are able to use it in older SQL Server versions. For instance, if you have a&amp;nbsp;database&amp;nbsp;in SQL Server 2008 R2 you can script it&amp;nbsp;and then&amp;nbsp;use it in SQL Server 2008 R2, 2008, 2005&amp;nbsp;or 2000. When you run the script in the new database environment, a new database is created or new tables etc.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;How do I script a database?&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;This is how you do it in SQL Server 2008 R2 so that you get a sql-script&amp;nbsp;which is backward compatible with SQL Server 2008. The script contains the database &lt;span style=&quot;text-decoration: underline;&quot;&gt;structure&lt;/span&gt; and the &lt;span style=&quot;text-decoration: underline;&quot;&gt;content&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;1. Open SQL Management Studio and right-click the database to script. Choose Tasks -&amp;gt; Generate Scripts...&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/link/7cda0b3b3cb44eaab843c2ed0c303679.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;1&quot; src=&quot;/link/7cda0b3b3cb44eaab843c2ed0c303679.jpg&quot; alt=&quot;1&quot; width=&quot;278&quot; height=&quot;193&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. Click Next on the Introduction.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/link/7b55727a0977439eb088aaa36d0131eb.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;2&quot; src=&quot;/link/7b55727a0977439eb088aaa36d0131eb.jpg&quot; alt=&quot;2&quot; width=&quot;286&quot; height=&quot;189&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3. Because we want the&amp;nbsp;whole database to be copied we choose to&amp;nbsp;script&amp;nbsp;entire database and all database objects:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href=&quot;/link/74b809a9aecb4cfbbee2004cb7210486.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;3&quot; src=&quot;/link/74b809a9aecb4cfbbee2004cb7210486.jpg&quot; alt=&quot;3&quot; width=&quot;291&quot; height=&quot;214&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;4.&amp;nbsp;Save the script to a specific location and to a single&amp;nbsp;file and then press the Advanced button:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/link/ad31b2245fa74df78fe7eff983ac8945.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;4&quot; src=&quot;/link/ad31b2245fa74df78fe7eff983ac8945.jpg&quot; alt=&quot;4&quot; width=&quot;300&quot; height=&quot;197&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;5. In the Advanced Scripting Options dialog there&#39;s a few&amp;nbsp;options that are important to change:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/link/eaa2e7a1e6184792aa088e5fec850b9f.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;5&quot; src=&quot;/link/eaa2e7a1e6184792aa088e5fec850b9f.jpg&quot; alt=&quot;5&quot; width=&quot;302&quot; height=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;* Script for Server Version - you can choose which SQL Server version to script to (make compatible with). In this case I choose SQL Server 2008.&lt;/p&gt;
&lt;p&gt;* Script USE DATABASE:&lt;br /&gt;- &lt;strong&gt;False &lt;/strong&gt;when the script is expected to be used in a different database (our case)&lt;br /&gt;- &lt;strong&gt;True&lt;/strong&gt; to make sure that database objects are created in the correct database&lt;/p&gt;
&lt;p&gt;* Types of data to script - Schema and data is our choice. If we don&#39;t choose data we will just get the database structure, i.e. the tables and schemas etc.&lt;/p&gt;
&lt;p&gt;There are many options.&amp;nbsp;For an explanation of each&amp;nbsp;go to&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ee210523.aspx&quot; target=&quot;_blank&quot;&gt;Generate and Publish Scripts Wizard (Advanced Scripting Options Page)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;6.&amp;nbsp;Review your selections. Click Next to run.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/link/aab81b7e86e24e6bbf6992cd0ef065a4.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;6&quot; src=&quot;/link/aab81b7e86e24e6bbf6992cd0ef065a4.jpg&quot; alt=&quot;6&quot; width=&quot;301&quot; height=&quot;217&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;7. You&#39;ll get a report on the result. If the result is&amp;nbsp;successful you&#39;ll find the script.sql file in the location you chose in a previous step (image 4).&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/link/9dd6cb430bbd442d95abcd801d98347a.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;7&quot; src=&quot;/link/9dd6cb430bbd442d95abcd801d98347a.jpg&quot; alt=&quot;7&quot; width=&quot;305&quot; height=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;8.&amp;nbsp;Execute the new script in SQL Server 2008 Management Studio.&amp;nbsp;A new database is created with the tables, content etc.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;SQL Server 2008 and 2005 scripting?&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;It&#39;s possible to create a script with structure and content in SQL Server 2008. Here&#39;s an &lt;a href=&quot;http://blog.sqlauthority.com/2009/07/29/sql-server-2008-copy-database-with-data-generate-t-sql-for-inserting-data-from-one-table-to-another-table/&quot; target=&quot;_blank&quot;&gt;example&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Scripting is&amp;nbsp;also possible&amp;nbsp;in SQL Server 2005&amp;nbsp;but I couldn&#39;t find any&amp;nbsp;data option. Maybe you are just able to script the structure and not the data (?).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Generate and Publish Scripts Wizard Help&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ee240853.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/ee240853.aspx&lt;/a&gt;&lt;/p&gt;</id><updated>2010-12-21T11:31:00.0000000Z</updated><summary type="html">Blog post</summary></entry></feed>