<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tim laqua dot com &#187; sql server</title>
	<atom:link href="http://timlaqua.com/tag/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://timlaqua.com</link>
	<description>Thoughts and Code from Tim Laqua</description>
	<lastBuildDate>Sun, 09 May 2010 15:25:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Script sp_configure Output To Migrate Settings Between SQL Servers</title>
		<link>http://timlaqua.com/2010/02/script-sp_configure-output-to-migrate-settings-between-sql-servers/</link>
		<comments>http://timlaqua.com/2010/02/script-sp_configure-output-to-migrate-settings-between-sql-servers/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 23:22:30 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=355</guid>
		<description><![CDATA[Sometimes when setting up a new server, all you want is for it to work and be configured exactly like the old server. In some cases, the new server is almost identical in every way already. If you've worked much with SQL Server, you know very well that there are a billion switches and knobs [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes when setting up a new server, all you want is for it to work and be configured exactly like the old server.  In some cases, the new server is almost identical in every way already.  If you've worked much with SQL Server, you know very well that there are a billion switches and knobs and every time you do this, you forget at least one.  I had a similar situation recently and figured I'd be lazy about it and just turned the output of sp_configure in to a script I could execute on the new server:<br />
<span id="more-355"></span><br />
<em>scriptSpConfigure.sql - run this on the old/source server</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'show advanced options'</span> , <span style="color: #000;">1</span>;
GO
<span style="color: #0000FF;">RECONFIGURE</span>;
GO
<span style="color: #0000FF;">DECLARE</span> @spConfigureOutput <span style="color: #0000FF;">TABLE</span>
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>name<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#91;</span>minimum<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span>
	,<span style="color: #808080;">&#91;</span>maximum<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span>
	,<span style="color: #808080;">&#91;</span>config_value<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span>
	,<span style="color: #808080;">&#91;</span>run_value<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @spConfigureOutput
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span>	<span style="color: #FF0000;">'EXEC sp_configure '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> name <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">', '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>config_value <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span>	@spConfigureOutput
GO
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'show advanced options'</span> , <span style="color: #000;">0</span>;
GO
<span style="color: #0000FF;">RECONFIGURE</span>;
GO</pre></div></div>

<p>Copy the selected rows and paste in to another SSMS window, add the show advanced options switch above and below - should end up with something like this after you <strong>remove all the settings you don't care about or don't want on the new server</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'show advanced options'</span> , <span style="color: #000;">1</span>;
GO
<span style="color: #0000FF;">RECONFIGURE</span>;
GO
&nbsp;
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'Ad Hoc Distributed Queries'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'Agent XPs'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'clr enabled'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'cost threshold for parallelism'</span>, <span style="color: #000;">5</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'cursor threshold'</span>, <span style="color: #808080;">-</span><span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'Database Mail XPs'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'default full-text language'</span>, <span style="color: #000;">1033</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'default trace enabled'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'fill factor (%)'</span>, <span style="color: #000;">80</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'ft crawl bandwidth (max)'</span>, <span style="color: #000;">100</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'ft notify bandwidth (max)'</span>, <span style="color: #000;">100</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'max full-text crawl range'</span>, <span style="color: #000;">4</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'max server memory (MB)'</span>, <span style="color: #000;">10000</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'max text repl size (B)'</span>, <span style="color: #000;">65536</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'min memory per query (KB)'</span>, <span style="color: #000;">1024</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'min server memory (MB)'</span>, <span style="color: #000;">10000</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'nested triggers'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'network packet size (B)'</span>, <span style="color: #000;">4096</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'PH timeout (s)'</span>, <span style="color: #000;">60</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'query wait (s)'</span>, <span style="color: #808080;">-</span><span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'remote access'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'remote login timeout (s)'</span>, <span style="color: #000;">20</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'remote query timeout (s)'</span>, <span style="color: #000;">900</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'scan for startup procs'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'server trigger recursion'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'SMO and DMO XPs'</span>, <span style="color: #000;">1</span>
&nbsp;
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'show advanced options'</span> , <span style="color: #000;">0</span>;
<span style="color: #0000FF;">RECONFIGURE</span>;
GO;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/02/script-sp_configure-output-to-migrate-settings-between-sql-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script RESTORE DATABASE &#8230; WITH MOVE Stub</title>
		<link>http://timlaqua.com/2010/02/script-restore-database-with-move-stub/</link>
		<comments>http://timlaqua.com/2010/02/script-restore-database-with-move-stub/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 18:29:26 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=349</guid>
		<description><![CDATA[I think most people setup the drives on their Development servers to match their Production servers - this is so that restores go smoothly and files go where they're supposed to, things match up nicely, etc. Unfortunately, when you create a full backup all the backup file contains is the logical name of all the [...]]]></description>
			<content:encoded><![CDATA[<p>I think most people setup the drives on their Development servers to match their Production servers - this is so that restores go smoothly and files go where they're supposed to, things match up nicely, etc.  Unfortunately, when you create a full backup all the backup file contains is the logical name of all the files - no physical paths.  This means that if the database doesn't exist on the destination server yet, the engine has absolutely no idea where to put the files or what to name them.</p>
<p>The following script can be executed in the context of the source (original) database that was backed up to script out the MOVE statements if your plan is to put the files in the same place on the destination server.<br />
<span id="more-349"></span><br />
<em>scriptRestoreWithMove.sql - run this in the context of the source database</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @MoveOption <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">TABLE</span>
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#91;</span>MoveOption<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'RESTORE DATABASE '</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #008080;">-- Edit this to match where you're restoring from</span>
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'FROM DISK = '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.bak'</span><span style="color: #FF0000;">''</span>  
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'WITH'</span>
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @MoveOption <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>MoveOption<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span>
    <span style="color: #FF0000;">'MOVE '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> a.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">' TO '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> a.<span style="color: #202020;">FILENAME</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">''</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>MOVE <span style="color: #0000FF;">OPTION</span><span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span>
    dbo.<span style="color: #202020;">sysfiles</span> a
&nbsp;
<span style="color: #0000FF;">DECLARE</span> 
	 @LastId <span style="color: #0000FF;">INT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
	,@MoveOptionText <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">EXISTS</span> <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">TOP</span> <span style="color: #000;">1</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">FROM</span> @MoveOption <span style="color: #0000FF;">WHERE</span> <span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&gt;</span> @LastId<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SELECT</span> 		<span style="color: #0000FF;">TOP</span> <span style="color: #000;">1</span>
			 @MoveOptionText <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>MoveOption<span style="color: #808080;">&#93;</span> 
			,@LastId <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span>
	<span style="color: #0000FF;">FROM</span>		@MoveOption
	<span style="color: #0000FF;">WHERE</span>		<span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&gt;</span> @LastId
	<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>	<span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">ASC</span>
&nbsp;
	<span style="color: #0000FF;">PRINT</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> @LastId <span style="color: #808080;">=</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">','</span> <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> @MoveOptionText
<span style="color: #0000FF;">END</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'GO'</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'ALTER DATABASE '</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' SET MULTI_USER'</span>
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'GO'</span></pre></div></div>

<p><em>And the output looks like this:</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">RESTORE</span> <span style="color: #0000FF;">DATABASE</span> AdventureWorksDW
<span style="color: #0000FF;">FROM</span> <span style="color: #0000FF;">DISK</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'AdventureWorksDW.bak'</span>
<span style="color: #0000FF;">WITH</span>
MOVE <span style="color: #FF0000;">'AdventureWorksDW_Data'</span> <span style="color: #0000FF;">TO</span> <span style="color: #FF0000;">'D:<span style="color: #000099; font-weight: bold;">\A</span>dventureWorksDW<span style="color: #000099; font-weight: bold;">\A</span>dventureWorksDW_Data.mdf'</span>
,MOVE <span style="color: #FF0000;">'AdventureWorksDW_Log'</span> <span style="color: #0000FF;">TO</span> <span style="color: #FF0000;">'T:<span style="color: #000099; font-weight: bold;">\A</span>dventureWorksDW<span style="color: #000099; font-weight: bold;">\A</span>dventureWorksDW_Log.LDF'</span>
GO
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> AdventureWorksDW <span style="color: #0000FF;">SET</span> MULTI_USER
GO</pre></div></div>

<p>If you end up wanting to do something similar with existing databases, make sure to add a command before the RESTORE to set SINGLE_USER mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/02/script-restore-database-with-move-stub/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
