<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.0.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Data Management - Author(s): SQLDenis</title>
		<link>http://blogs.lessthandot.com/index.php/DataMgmt/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2" />
		<description></description>
		<language>en-GB</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.0.3"/>
		<ttl>60</ttl>
				<item>
			<title>SQL Puzzle:  RIGHT without using the RIGHT function</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/sql-puzzle-right-without-using</link>
			<pubDate>Wed, 22 May 2013 07:44:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="main">Database Programming</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">2197@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;I haven&#039;t done a puzzle for a long time so I figured let&#039;s do a simple one. Return the right 6 characters of the column but without using the RIGHT function.&lt;/p&gt;


&lt;p&gt;Here is what the table looks like&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb17850&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; #Puzzle&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SomeCol &lt;span style=&quot;color: #0000FF;&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &amp;nbsp;#Puzzle &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;AAAAAAA&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &amp;nbsp;#Puzzle &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; BBBBBB&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &amp;nbsp;#Puzzle &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;CCCCCC&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &amp;nbsp;#Puzzle &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; DDDDD &#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &amp;nbsp;#Puzzle &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;NULL&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &amp;nbsp;#Puzzle &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb23298&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see some rows start with spaces and some end with spaces, one row has the NULL value&lt;br /&gt;
The output should be a Z followed by the right 6 characters from the column + the length of the column (not the length of the 6 characters that you are returning)&lt;/p&gt;

&lt;p&gt;Here is what the output should look like&lt;/p&gt;
&lt;pre&gt;ZAAAAAA7
ZBBBBBB7
ZCCCCC 7
ZDDDDD 7
Z0
Z      7&lt;/pre&gt;

&lt;p&gt;As you can see spaces should remain and when the value is NULL then there should be a blank. The length for the row with the NULL value should be 0, you cannot hardcode 7 for the length, you have to calculate it.&lt;/p&gt;

&lt;p&gt;Post your solution(s) in the comment section, remember no RIGHT function. Let&#039;s see how many different ways you can come up with to do this&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/sql-puzzle-right-without-using&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>I haven't done a puzzle for a long time so I figured let's do a simple one. Return the right 6 characters of the column but without using the RIGHT function.</p>


<p>Here is what the table looks like</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb97961'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb97961','cb5262'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb97961" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #Puzzle<span style="color: #808080;">&#40;</span>SomeCol <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">7</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> &nbsp;#Puzzle <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'AAAAAAA'</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> &nbsp;#Puzzle <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">' BBBBBB'</span><span style="color: #808080;">&#41;</span></li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> &nbsp;#Puzzle <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'CCCCCC'</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> &nbsp;#Puzzle <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">' DDDDD '</span><span style="color: #808080;">&#41;</span></li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> &nbsp;#Puzzle <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span>NULL<span style="color: #808080;">&#41;</span></li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> &nbsp;#Puzzle <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">' &nbsp; &nbsp; &nbsp; '</span><span style="color: #808080;">&#41;</span></li></ol></div><div id="cb5262" style="display: none; color: red;"></div></div></div>

<p>As you can see some rows start with spaces and some end with spaces, one row has the NULL value<br />
The output should be a Z followed by the right 6 characters from the column + the length of the column (not the length of the 6 characters that you are returning)</p>

<p>Here is what the output should look like</p>
<pre>ZAAAAAA7
ZBBBBBB7
ZCCCCC 7
ZDDDDD 7
Z0
Z      7</pre>

<p>As you can see spaces should remain and when the value is NULL then there should be a blank. The length for the row with the NULL value should be 0, you cannot hardcode 7 for the length, you have to calculate it.</p>

<p>Post your solution(s) in the comment section, remember no RIGHT function. Let's see how many different ways you can come up with to do this</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/sql-puzzle-right-without-using">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/sql-puzzle-right-without-using#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2197</wfw:commentRss>
		</item>
				<item>
			<title>SQL Server Database owner ~~UNKNOWN~~</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-database-owner-unknown</link>
			<pubDate>Tue, 14 May 2013 10:02:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="alt">Database Administration</category>
<category domain="main">Microsoft SQL Server Admin</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">2195@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Today I was checking an older server and decided to run sp_helpdb. On a bunch of databases I noticed that the owner was ~~UNKNOWN~~. The only reason I noticed this was when I tried to look at a specific database which is mirrored. I was greeted with this dialog box&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;Cannot show requested dialog.&lt;/p&gt;

&lt;p&gt;Additional information:&lt;br /&gt;
  Cannot show requested dialog.(SqlMgmt)&lt;br /&gt;
    Property Owner is not available for Database&#039;[Your Database Name]&#039;. This property may not exist for this &lt;br /&gt;
    object, or may not be retrievable due to insufficient access rights. (Microsoft.SqlServer.Smo)&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;What does this mean, was the server hacked and someone changed the owner? No, what this means is that the owner of the database was a windows account which no longer exists, the person probably left and the account was removed.&lt;/p&gt;

&lt;p&gt;All you have to do is change the owner to a valid login&lt;/p&gt;

&lt;p&gt;If you want it to be sa or a sql login, this example is for sa, change sa to something else if you want a different sql login&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb58203&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;ALTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AUTHORIZATION&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;DATABASE&lt;/span&gt;::&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;YourDatabase&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TO&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;sa&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb72110&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you want it to be a windows login, you can do the following&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb45469&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;ALTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AUTHORIZATION&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;DATABASE&lt;/span&gt;::&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;YourDatabase&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TO&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Domain&lt;/span&gt;\Login&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb92813&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;If you run sp_helpdb now, you will see that the owner has been changed&lt;/p&gt;

&lt;p&gt;If you are old school, you can also use sp_changedbowner to make the change&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb68214&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;USE&lt;/span&gt; YourDatabase&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_changedbowner&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;sa&#039;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb79235&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-database-owner-unknown&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Today I was checking an older server and decided to run sp_helpdb. On a bunch of databases I noticed that the owner was ~~UNKNOWN~~. The only reason I noticed this was when I tried to look at a specific database which is mirrored. I was greeted with this dialog box</p>


<blockquote><p>Cannot show requested dialog.</p>

<p>Additional information:<br />
  Cannot show requested dialog.(SqlMgmt)<br />
    Property Owner is not available for Database'[Your Database Name]'. This property may not exist for this <br />
    object, or may not be retrievable due to insufficient access rights. (Microsoft.SqlServer.Smo)</p></blockquote>

<p>What does this mean, was the server hacked and someone changed the owner? No, what this means is that the owner of the database was a windows account which no longer exists, the person probably left and the account was removed.</p>

<p>All you have to do is change the owner to a valid login</p>

<p>If you want it to be sa or a sql login, this example is for sa, change sa to something else if you want a different sql login</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb22304'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb22304','cb31099'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb22304" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">AUTHORIZATION</span> <span style="color: #0000FF;">ON</span> <span style="color: #0000FF;">DATABASE</span>::<span style="color: #808080;">&#91;</span>YourDatabase<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">TO</span> <span style="color: #808080;">&#91;</span>sa<span style="color: #808080;">&#93;</span>;</li></ol></div><div id="cb31099" style="display: none; color: red;"></div></div></div>

<p>If you want it to be a windows login, you can do the following</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb7899'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb7899','cb35795'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb7899" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">AUTHORIZATION</span> <span style="color: #0000FF;">ON</span> <span style="color: #0000FF;">DATABASE</span>::<span style="color: #808080;">&#91;</span>YourDatabase<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">TO</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Domain</span>\Login<span style="color: #808080;">&#93;</span>;</li></ol></div><div id="cb35795" style="display: none; color: red;"></div></div></div>


<p>If you run sp_helpdb now, you will see that the owner has been changed</p>

<p>If you are old school, you can also use sp_changedbowner to make the change</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb64875'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb64875','cb23831'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb64875" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">USE</span> YourDatabase</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_changedbowner</span> <span style="color: #FF0000;">'sa'</span></li></ol></div><div id="cb23831" style="display: none; color: red;"></div></div></div><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-database-owner-unknown">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-database-owner-unknown#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2195</wfw:commentRss>
		</item>
				<item>
			<title>Fixing a SQL Server could not spawn FRunCM thread error</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/fixing-a-sql-server-could</link>
			<pubDate>Tue, 30 Apr 2013 12:28:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="main">Microsoft SQL Server Admin</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">2188@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;I had to change the domain account on some SQL Server boxes that we have. After I changed the account on one machine from DomainName\User to DomainName\NewUser SQL Server wouldn&#039;t start up&lt;/p&gt;

&lt;p&gt;In the error log I saw the following messages&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Server      Error: 17190, Severity: 16, State: 1.&lt;br /&gt;
2013-04-30 12:42:06.11 Server      Initializing the FallBack certificate failed with error code: 1, state: 1, error number: -2146893802.&lt;br /&gt;
2013-04-30 12:42:06.11 Server      Unable to initialize SSL encryption because a valid certificate could not be found, and it is not possible to create a self-signed certificate.&lt;br /&gt;
2013-04-30 12:42:06.11 Server      Error: 17182, Severity: 16, State: 1.&lt;br /&gt;
2013-04-30 12:42:06.11 Server      TDSSNIClient initialization failed with error 0x80092004, status code 0x80. Reason: Unable to initialize SSL support. Cannot find object or property.&lt;/p&gt;

&lt;p&gt;2013-04-30 12:42:06.11 Server      Error: 17182, Severity: 16, State: 1.&lt;br /&gt;
2013-04-30 12:42:06.11 Server      TDSSNIClient initialization failed with error 0x80092004, status code 0x1. Reason: Initialization failed with an infrastructure error. Check for previous errors. Cannot find object or property.&lt;/p&gt;

&lt;p&gt;2013-04-30 12:42:06.11 Server      Error: 17826, Severity: 18, State: 3.&lt;br /&gt;
2013-04-30 12:42:06.11 Server      Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.&lt;br /&gt;
2013-04-30 12:42:06.11 Server      Error: 17120, Severity: 16, State: 1.&lt;br /&gt;
2013-04-30 12:42:06.11 Server      SQL Server could not spawn FRunCM thread. Check the SQL Server error log and the Windows event logs for information about possible related problems.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;We are not using encryption, VIA is disabled as well. After trying all kinds of different things I notice that when logging on with this profile on the box there was an error. Something about that the profile couldn&#039;t be created and a temporary profile would be used instead&lt;/p&gt;

&lt;p&gt;In the end I had to wipe out the user profile from the box&lt;/p&gt;


&lt;p&gt;You do that by following these steps&lt;/p&gt;

&lt;p&gt;Right click on computer, select Properties&lt;br /&gt;
Click on Advanced System Settings&lt;br /&gt;
Select the  Advanced Tab&lt;br /&gt;
On the user profiles section click on Settings&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/UserProfile.PNG?mtime=1367323923&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/UserProfile.PNG?mtime=1367323923&quot; width=&quot;399&quot; height=&quot;451&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Select the profile and hit Delete&lt;/p&gt;

&lt;p&gt;If you try to log in as that user, the profile will be recreated.&lt;/p&gt;

&lt;p&gt;Now when I tried to start SQL Server again, the errors were not there and SQL Server started up without a problem&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/fixing-a-sql-server-could&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>I had to change the domain account on some SQL Server boxes that we have. After I changed the account on one machine from DomainName\User to DomainName\NewUser SQL Server wouldn't start up</p>

<p>In the error log I saw the following messages</p>

<blockquote><p>Server      Error: 17190, Severity: 16, State: 1.<br />
2013-04-30 12:42:06.11 Server      Initializing the FallBack certificate failed with error code: 1, state: 1, error number: -2146893802.<br />
2013-04-30 12:42:06.11 Server      Unable to initialize SSL encryption because a valid certificate could not be found, and it is not possible to create a self-signed certificate.<br />
2013-04-30 12:42:06.11 Server      Error: 17182, Severity: 16, State: 1.<br />
2013-04-30 12:42:06.11 Server      TDSSNIClient initialization failed with error 0x80092004, status code 0x80. Reason: Unable to initialize SSL support. Cannot find object or property.</p>

<p>2013-04-30 12:42:06.11 Server      Error: 17182, Severity: 16, State: 1.<br />
2013-04-30 12:42:06.11 Server      TDSSNIClient initialization failed with error 0x80092004, status code 0x1. Reason: Initialization failed with an infrastructure error. Check for previous errors. Cannot find object or property.</p>

<p>2013-04-30 12:42:06.11 Server      Error: 17826, Severity: 18, State: 3.<br />
2013-04-30 12:42:06.11 Server      Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.<br />
2013-04-30 12:42:06.11 Server      Error: 17120, Severity: 16, State: 1.<br />
2013-04-30 12:42:06.11 Server      SQL Server could not spawn FRunCM thread. Check the SQL Server error log and the Windows event logs for information about possible related problems.</p></blockquote>

<p>We are not using encryption, VIA is disabled as well. After trying all kinds of different things I notice that when logging on with this profile on the box there was an error. Something about that the profile couldn't be created and a temporary profile would be used instead</p>

<p>In the end I had to wipe out the user profile from the box</p>


<p>You do that by following these steps</p>

<p>Right click on computer, select Properties<br />
Click on Advanced System Settings<br />
Select the  Advanced Tab<br />
On the user profiles section click on Settings</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/UserProfile.PNG?mtime=1367323923"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/UserProfile.PNG?mtime=1367323923" width="399" height="451" /></a></div>

<p>Select the profile and hit Delete</p>

<p>If you try to log in as that user, the profile will be recreated.</p>

<p>Now when I tried to start SQL Server again, the errors were not there and SQL Server started up without a problem</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/fixing-a-sql-server-could">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/fixing-a-sql-server-could#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2188</wfw:commentRss>
		</item>
				<item>
			<title>Where to find the xtype info for SQL Server in a table</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/where-to-find-the-xtype</link>
			<pubDate>Fri, 26 Apr 2013 14:48:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="alt">Database Programming</category>
<category domain="main">Microsoft SQL Server Admin</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">2185@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;If you look at the sys.sysobjects view, you will see a xtype column listed&lt;/p&gt;

&lt;p&gt;Object type. Can be one of the following object types:&lt;br /&gt;
AF = Aggregate function (CLR)&lt;br /&gt;
C = CHECK constraint&lt;br /&gt;
D = Default or DEFAULT constraint&lt;br /&gt;
F = FOREIGN KEY constraint&lt;br /&gt;
L = Log&lt;br /&gt;
FN = Scalar function&lt;br /&gt;
FS = Assembly (CLR) scalar-function&lt;br /&gt;
FT = Assembly (CLR) table-valued function&lt;br /&gt;
IF = In-lined table-function&lt;br /&gt;
IT = Internal table&lt;br /&gt;
P = Stored procedure&lt;br /&gt;
PC = Assembly (CLR) stored-procedure&lt;br /&gt;
PK = PRIMARY KEY constraint (type is K)&lt;br /&gt;
RF = Replication filter stored procedure&lt;br /&gt;
S = System table&lt;br /&gt;
SN = Synonym&lt;br /&gt;
SQ = Service queue&lt;br /&gt;
TA = Assembly (CLR) DML trigger&lt;br /&gt;
TF = Table function&lt;br /&gt;
TR = SQL DML Trigger&lt;br /&gt;
TT = Table type&lt;br /&gt;
U = User table&lt;br /&gt;
UQ = UNIQUE constraint (type is K)&lt;br /&gt;
V = View&lt;br /&gt;
X = Extended stored procedure&lt;/p&gt;


&lt;p&gt;However there is no table in SQL Server that holds this info....or is there?&lt;/p&gt;

&lt;p&gt;I answered &lt;a href=&quot;http://stackoverflow.com/questions/16243857/is-there-a-table-that-holds-the-listing-of-xtype-descriptions&quot;&gt;this question&lt;/a&gt; today and decided to share here as well&lt;/p&gt;


&lt;p&gt;Here is how you can find that info, you can use my favorite table spt_values&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb8375&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; name&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; master..&lt;span style=&quot;color: #202020;&quot;&gt;spt_values&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;WHERE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;type&lt;/span&gt; = &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;O9T&#039;&lt;/span&gt;&lt;br /&gt;AND number &amp;nbsp;= &lt;span style=&quot;color: #000;&quot;&gt;-1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb3077&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is the output&lt;/p&gt;

&lt;p&gt;AF: aggregate function&lt;br /&gt;
AP: application&lt;br /&gt;
C : check cns&lt;br /&gt;
D : default (maybe cns)&lt;br /&gt;
EN: event notification&lt;br /&gt;
F : foreign key cns&lt;br /&gt;
FN: scalar function&lt;br /&gt;
FS: assembly scalar function&lt;br /&gt;
FT: assembly table function&lt;br /&gt;
IF: inline function&lt;br /&gt;
IS: inline scalar function&lt;br /&gt;
IT: internal table&lt;br /&gt;
L : log&lt;br /&gt;
P : stored procedure&lt;br /&gt;
PC : assembly stored procedure&lt;br /&gt;
PK: primary key cns&lt;br /&gt;
R : rule&lt;br /&gt;
RF: replication filter proc&lt;br /&gt;
S : system table&lt;br /&gt;
SN: synonym&lt;br /&gt;
SQ: queue&lt;br /&gt;
TA: assembly trigger&lt;br /&gt;
TF: table function&lt;br /&gt;
TR: trigger&lt;br /&gt;
U : user table&lt;br /&gt;
UQ: unique key cns&lt;br /&gt;
V : view&lt;br /&gt;
X : extended stored proc&lt;/p&gt;


&lt;p&gt;Now if you want to split it into two columns, you can use the LEFT and RIGHT functions together with the PATINDEX function&lt;/p&gt;


&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb67711&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;LEFT&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name,&lt;span style=&quot;color: #FF00FF;&quot;&gt;PATINDEX&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;%:%&#039;&lt;/span&gt;,name&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;-1&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; xtype,&lt;br /&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;RIGHT&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name, &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;LEN&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; - &lt;span style=&quot;color: #FF00FF;&quot;&gt;PATINDEX&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;%:%&#039;&lt;/span&gt;,name&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; Description&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; master..&lt;span style=&quot;color: #202020;&quot;&gt;spt_values&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;WHERE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;type&lt;/span&gt; = &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;O9T&#039;&lt;/span&gt;&lt;br /&gt;AND number &amp;nbsp;= &lt;span style=&quot;color: #000;&quot;&gt;-1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb92554&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here is the result&lt;/p&gt;

&lt;pre&gt;xtype	Description
AF	 aggregate function
AP	 application
C 	 check cns
D 	 default (maybe cns)
EN	 event notification
F 	 foreign key cns
FN	 scalar function
FS	 assembly scalar function
FT	 assembly table function
IF	 inline function
IS	 inline scalar function
IT	 internal table
L 	 log
P 	 stored procedure
PC 	 assembly stored procedure
PK	 primary key cns
R 	 rule
RF	 replication filter proc
S 	 system table
SN	 synonym
SQ	 queue
TA	 assembly trigger
TF	 table function
TR	 trigger
U 	 user table
UQ	 unique key cns
V 	 view
X 	 extended stored proc&lt;/pre&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/where-to-find-the-xtype&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>If you look at the sys.sysobjects view, you will see a xtype column listed</p>

<p>Object type. Can be one of the following object types:<br />
AF = Aggregate function (CLR)<br />
C = CHECK constraint<br />
D = Default or DEFAULT constraint<br />
F = FOREIGN KEY constraint<br />
L = Log<br />
FN = Scalar function<br />
FS = Assembly (CLR) scalar-function<br />
FT = Assembly (CLR) table-valued function<br />
IF = In-lined table-function<br />
IT = Internal table<br />
P = Stored procedure<br />
PC = Assembly (CLR) stored-procedure<br />
PK = PRIMARY KEY constraint (type is K)<br />
RF = Replication filter stored procedure<br />
S = System table<br />
SN = Synonym<br />
SQ = Service queue<br />
TA = Assembly (CLR) DML trigger<br />
TF = Table function<br />
TR = SQL DML Trigger<br />
TT = Table type<br />
U = User table<br />
UQ = UNIQUE constraint (type is K)<br />
V = View<br />
X = Extended stored procedure</p>


<p>However there is no table in SQL Server that holds this info....or is there?</p>

<p>I answered <a href="http://stackoverflow.com/questions/16243857/is-there-a-table-that-holds-the-listing-of-xtype-descriptions">this question</a> today and decided to share here as well</p>


<p>Here is how you can find that info, you can use my favorite table spt_values</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb34629'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb34629','cb11475'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb34629" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> name</li><li style="" class="li2"><span style="color: #0000FF;">FROM</span> master..<span style="color: #202020;">spt_values</span></li><li style="" class="li1"><span style="color: #0000FF;">WHERE</span> <span style="color: #0000FF;">type</span> = <span style="color: #FF0000;">'O9T'</span></li><li style="" class="li2">AND number &nbsp;= <span style="color: #000;">-1</span></li></ol></div><div id="cb11475" style="display: none; color: red;"></div></div></div>

<p>This is the output</p>

<p>AF: aggregate function<br />
AP: application<br />
C : check cns<br />
D : default (maybe cns)<br />
EN: event notification<br />
F : foreign key cns<br />
FN: scalar function<br />
FS: assembly scalar function<br />
FT: assembly table function<br />
IF: inline function<br />
IS: inline scalar function<br />
IT: internal table<br />
L : log<br />
P : stored procedure<br />
PC : assembly stored procedure<br />
PK: primary key cns<br />
R : rule<br />
RF: replication filter proc<br />
S : system table<br />
SN: synonym<br />
SQ: queue<br />
TA: assembly trigger<br />
TF: table function<br />
TR: trigger<br />
U : user table<br />
UQ: unique key cns<br />
V : view<br />
X : extended stored proc</p>


<p>Now if you want to split it into two columns, you can use the LEFT and RIGHT functions together with the PATINDEX function</p>


<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb77351'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb77351','cb18979'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb77351" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">LEFT</span><span style="color: #808080;">&#40;</span>name,<span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'%:%'</span>,name<span style="color: #808080;">&#41;</span><span style="color: #000;">-1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> xtype,</li><li style="" class="li2"><span style="color: #FF00FF;">RIGHT</span><span style="color: #808080;">&#40;</span>name, <span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>name<span style="color: #808080;">&#41;</span> - <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'%:%'</span>,name<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> Description</li><li style="" class="li1"><span style="color: #0000FF;">FROM</span> master..<span style="color: #202020;">spt_values</span></li><li style="" class="li2"><span style="color: #0000FF;">WHERE</span> <span style="color: #0000FF;">type</span> = <span style="color: #FF0000;">'O9T'</span></li><li style="" class="li1">AND number &nbsp;= <span style="color: #000;">-1</span></li></ol></div><div id="cb18979" style="display: none; color: red;"></div></div></div>

<p>Here is the result</p>

<pre>xtype	Description
AF	 aggregate function
AP	 application
C 	 check cns
D 	 default (maybe cns)
EN	 event notification
F 	 foreign key cns
FN	 scalar function
FS	 assembly scalar function
FT	 assembly table function
IF	 inline function
IS	 inline scalar function
IT	 internal table
L 	 log
P 	 stored procedure
PC 	 assembly stored procedure
PK	 primary key cns
R 	 rule
RF	 replication filter proc
S 	 system table
SN	 synonym
SQ	 queue
TA	 assembly trigger
TF	 table function
TR	 trigger
U 	 user table
UQ	 unique key cns
V 	 view
X 	 extended stored proc</pre><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/where-to-find-the-xtype">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/where-to-find-the-xtype#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2185</wfw:commentRss>
		</item>
				<item>
			<title>Using a Dedicated Administrator Connection via SSMS</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/using-a-dedicated-administrator-connection</link>
			<pubDate>Sun, 07 Apr 2013 13:55:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="alt">Database Programming</category>
<category domain="main">Microsoft SQL Server Admin</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">2172@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;If you need to use a Dedicated Administrator Connection (DAC) via SSMS, you can&#039;t just use the Connect Object Explorer, if you try you will get the following error&lt;/p&gt;

&lt;p&gt;Dedicated administrator connections are not supported via SSMS as it establishes multiple connections by design. (Microsoft.SqlServer.Management.SqlStudio.Explorer)&lt;br /&gt;
 &lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Dac.PNG?mtime=1365341742&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Dac.PNG?mtime=1365341742&quot; width=&quot;619&quot; height=&quot;174&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;So what do you do? You can connect from within SSMS, you need to click on the  &lt;code&gt;Database Engine Query&lt;/code&gt; icon&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Dac2.PNG?mtime=1365342094&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Dac2.PNG?mtime=1365342094&quot; width=&quot;416&quot; height=&quot;87&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Prefix the servername with Admin: Instead of &lt;strong&gt;(local)&lt;/strong&gt;, you would do &lt;strong&gt;Admin:(local)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;
Another way to connect is by using sqlcmd with the command-line option A&lt;br /&gt;
Here is an example with a username and password&lt;/p&gt;

&lt;p&gt;sqlcmd -S ServerName -U sa -P Password &amp;#8211;A&lt;/p&gt;

&lt;p&gt;You can also use a trusted connection&lt;/p&gt;

&lt;p&gt;sqlcmd -S (local) -E -A&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/dac3.PNG?mtime=1365343123&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/dac3.PNG?mtime=1365343123&quot; width=&quot;671&quot; height=&quot;142&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;p&gt;If you want to know more about DAC, check out &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms189595(v=sql.110).aspx&quot;&gt;Using a Dedicated Administrator Connection&lt;/a&gt;&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/using-a-dedicated-administrator-connection&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>If you need to use a Dedicated Administrator Connection (DAC) via SSMS, you can't just use the Connect Object Explorer, if you try you will get the following error</p>

<p>Dedicated administrator connections are not supported via SSMS as it establishes multiple connections by design. (Microsoft.SqlServer.Management.SqlStudio.Explorer)<br />
 </p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Dac.PNG?mtime=1365341742"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Dac.PNG?mtime=1365341742" width="619" height="174" /></a></div>

<p>So what do you do? You can connect from within SSMS, you need to click on the  <code>Database Engine Query</code> icon</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Dac2.PNG?mtime=1365342094"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Dac2.PNG?mtime=1365342094" width="416" height="87" /></a></div>

<p>Prefix the servername with Admin: Instead of <strong>(local)</strong>, you would do <strong>Admin:(local)</strong></p>

<p><br /><br />
Another way to connect is by using sqlcmd with the command-line option A<br />
Here is an example with a username and password</p>

<p>sqlcmd -S ServerName -U sa -P Password &#8211;A</p>

<p>You can also use a trusted connection</p>

<p>sqlcmd -S (local) -E -A</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/dac3.PNG?mtime=1365343123"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/dac3.PNG?mtime=1365343123" width="671" height="142" /></a></div>


<p>If you want to know more about DAC, check out <a href="http://msdn.microsoft.com/en-us/library/ms189595(v=sql.110).aspx">Using a Dedicated Administrator Connection</a></p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/using-a-dedicated-administrator-connection">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/using-a-dedicated-administrator-connection#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2172</wfw:commentRss>
		</item>
				<item>
			<title>BCP all tables into files from a database</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/bcp-all-tables-into-files</link>
			<pubDate>Sun, 31 Mar 2013 11:42:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="alt">Database Programming</category>
<category domain="alt">Database Administration</category>
<category domain="main">Microsoft SQL Server Admin</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">2168@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Sometimes you want to dump the data from all the tables in a database into files. There is really no fast and easy way to do this. Fortunately it is very easy to roll your own solution. Let&#039;s look at what we need to do&lt;/p&gt;

&lt;p&gt;1) we need to grab all the tables in the database&lt;br /&gt;
2) we need to make sure that the table names are valid&lt;br /&gt;
3) we need to specify the output directory&lt;br /&gt;
4) we need to make sure that the file names are valid&lt;br /&gt;
5) we need to specify how we are connecting to SQL Server&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;We need to grab all the tables in the database&lt;/strong&gt;&lt;br /&gt;
The query to grab all the names is&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb92637&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; name &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #00AF00;&quot;&gt;tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb93244&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However if you use schemas then that won&#039;t work, you need to do the following&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb16739&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;SCHEMA_ID&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;,name &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #00AF00;&quot;&gt;tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb79189&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The reason for this is that you can have the same table name in different schemas, you would only get the one in the default schema&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;We need to make sure that the table names are valid&lt;/strong&gt;&lt;br /&gt;
Sometimes you have table names that have spaces in them or start perhaps with a number. If you have tables like that, you have to put brackets around it. One way to put brackets around tables names is to just do something like this &lt;code&gt;&#039;[&#039; + name + &#039;]&#039;&lt;/code&gt; another way is to use the QUOTENAME function&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb30613&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &amp;nbsp; &lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;SCHEMA_ID&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.&#039;&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #00AF00;&quot;&gt;tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb35108&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;We need to specify the output directory&lt;/strong&gt;&lt;br /&gt;
You need to tell bcp where to dump the files&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We need to make sure that the file names are valid&lt;/strong&gt;&lt;br /&gt;
Windows does not allow for certain characters in file names&lt;/p&gt;

&lt;p&gt;&lt; (less than)&lt;br /&gt;
&gt; (greater than)&lt;br /&gt;
: (colon)&lt;br /&gt;
&quot; (double quote)&lt;br /&gt;
/ (forward slash)&lt;br /&gt;
\ (backslash)&lt;br /&gt;
| (vertical bar or pipe)&lt;br /&gt;
? (question mark)&lt;br /&gt;
* (asterisk)&lt;br /&gt;
If you have to give the files to be imported on a Linux/unix systems then you want to eliminate spaces as well&lt;br /&gt;
In that case you end up with something like this&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb86&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;schema_id&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; + &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;_&#039;&lt;/span&gt; &lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #00AF00;&quot;&gt;tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb90079&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;We need to specify how we are connecting to SQL Server&lt;/strong&gt;&lt;br /&gt;
You can use password and username to connect to SQL Server or you can use a trusted connections&lt;/p&gt;




&lt;h2&gt;Putting it all together&lt;/h2&gt;

&lt;p&gt;Here is the complete query&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb44025&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;EXEC xp_cmdshell &#039;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp &#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;--bcp&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;DB_NAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.&#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;--database name&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;SCHEMA_ID&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.&#039;&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- schema&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- table&lt;/span&gt;&lt;br /&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; out c:\temp\&#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- output directory&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;schema_id&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; + &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;_&#039;&lt;/span&gt; &lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- file name&lt;/span&gt;&lt;br /&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.txt -T -c&#039;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;-- extension, security &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #00AF00;&quot;&gt;tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb57918&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Running that query will give you something like the following&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb28185&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[Production].[ScrapReason] out c:\temp\Production_ScrapReason.txt -T -c&#039;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[HumanResources].[Shift] out c:\temp\HumanResources_Shift.txt -T -c&#039;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[Production].[ProductCategory] out c:\temp\Production_ProductCategory.txt -T -c&#039;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[Purchasing].[ShipMethod] out c:\temp\Purchasing_ShipMethod.txt -T -c&#039;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[Production].[ProductCostHistory] out c:\temp\Production_ProductCostHistory.txt -T -c&#039;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb31312&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;You can now take that and run it. When you run it, you will see the following output&lt;/p&gt;

&lt;p&gt;NULL&lt;br /&gt;
Starting copy...&lt;br /&gt;
NULL&lt;br /&gt;
32 rows copied.&lt;br /&gt;
Network packet size (bytes): 4096&lt;br /&gt;
Clock Time (ms.) Total     : 1      Average : (32000.00 rows per sec.)&lt;br /&gt;
NULL&lt;/p&gt;

&lt;p&gt;Sometines you don&#039;t want to see that output,In that case we need to &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/supressing-xp_cmdshell-output&quot;&gt;suppress xp_cmdshell output&lt;/a&gt;, you do this by adding ,no_output at the end&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb94852&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;EXEC xp_cmdshell &#039;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp &#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;--bcp&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;DB_NAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.&#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;--database name&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;SCHEMA_ID&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.&#039;&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- schema&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- table&lt;/span&gt;&lt;br /&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; out c:\temp\&#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- output directory&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;schema_id&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; + &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;_&#039;&lt;/span&gt; &lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- file name&lt;/span&gt;&lt;br /&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.txt -T -c&#039;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;,no_output&#039;&lt;/span&gt; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;-- extension, security, no output &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #00AF00;&quot;&gt;tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb28214&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;Now you get something like the following&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb23001&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[Production].[ScrapReason] out c:\temp\Production_ScrapReason.txt -T -c&#039;&lt;/span&gt;,no_output&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[HumanResources].[Shift] out c:\temp\HumanResources_Shift.txt -T -c&#039;&lt;/span&gt;,no_output&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[Production].[ProductCategory] out c:\temp\Production_ProductCategory.txt -T -c&#039;&lt;/span&gt;,no_output&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;xp_cmdshell&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp [AdventureWorks2012].[Purchasing].[ShipMethod] out c:\temp\Purchasing_ShipMethod.txt -T -c&#039;&lt;/span&gt;,no_output&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb99124&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There you have it, a quick and dirty version to dump all the tables into files.&lt;/p&gt;

&lt;p&gt;You can of course enhance this by creating a proc where you can specify only a certain schema, delimiters, how to connect etc etc&lt;/p&gt;

&lt;p&gt;If you don&#039;t want to use xp_cmdshell, you can also dump the results without the xp_cmdshell part into a BAT file and call it from DOS or PowerShell&lt;/p&gt;

&lt;p&gt;That query would look like this&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb67692&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;bcp &#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;--bcp&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;DB_NAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.&#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;--database name&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;SCHEMA_ID&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.&#039;&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- schema&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;QUOTENAME&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- table&lt;/span&gt;&lt;br /&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; out c:\temp\&#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- output directory&lt;/span&gt;&lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;SCHEMA_NAME&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;schema_id&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; + &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;_&#039;&lt;/span&gt; &lt;br /&gt;+ &amp;nbsp;&lt;span style=&quot;color: #FF00FF;&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;name,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039; &#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;-- file name&lt;/span&gt;&lt;br /&gt;+ &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;.txt -T -c&#039;&lt;/span&gt; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;-- extension, security, &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #00AF00;&quot;&gt;tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb51150&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/bcp-all-tables-into-files&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Sometimes you want to dump the data from all the tables in a database into files. There is really no fast and easy way to do this. Fortunately it is very easy to roll your own solution. Let's look at what we need to do</p>

<p>1) we need to grab all the tables in the database<br />
2) we need to make sure that the table names are valid<br />
3) we need to specify the output directory<br />
4) we need to make sure that the file names are valid<br />
5) we need to specify how we are connecting to SQL Server</p>


<p><strong>We need to grab all the tables in the database</strong><br />
The query to grab all the names is</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb70390'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb70390','cb63297'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb70390" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> name <span style="color: #0000FF;">FROM</span> <span style="color: #00AF00;">sys</span>.<span style="color: #00AF00;">tables</span></li></ol></div><div id="cb63297" style="display: none; color: red;"></div></div></div>

<p>However if you use schemas then that won't work, you need to do the following</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb20403'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb20403','cb75201'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb20403" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SCHEMA_ID</span><span style="color: #808080;">&#41;</span>,name </li><li style="" class="li2"><span style="color: #0000FF;">FROM</span> <span style="color: #00AF00;">sys</span>.<span style="color: #00AF00;">tables</span></li></ol></div><div id="cb75201" style="display: none; color: red;"></div></div></div>
<p>The reason for this is that you can have the same table name in different schemas, you would only get the one in the default schema</p>


<p><strong>We need to make sure that the table names are valid</strong><br />
Sometimes you have table names that have spaces in them or start perhaps with a number. If you have tables like that, you have to put brackets around it. One way to put brackets around tables names is to just do something like this <code>'[' + name + ']'</code> another way is to use the QUOTENAME function</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb71961'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb71961','cb27547'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb71961" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> &nbsp; <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SCHEMA_ID</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>+ <span style="color: #FF0000;">'.'</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>name<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #00AF00;">sys</span>.<span style="color: #00AF00;">tables</span></li></ol></div><div id="cb27547" style="display: none; color: red;"></div></div></div>

<p><strong>We need to specify the output directory</strong><br />
You need to tell bcp where to dump the files</p>

<p><strong>We need to make sure that the file names are valid</strong><br />
Windows does not allow for certain characters in file names</p>

<p>< (less than)<br />
> (greater than)<br />
: (colon)<br />
" (double quote)<br />
/ (forward slash)<br />
\ (backslash)<br />
| (vertical bar or pipe)<br />
? (question mark)<br />
* (asterisk)<br />
If you have to give the files to be imported on a Linux/unix systems then you want to eliminate spaces as well<br />
In that case you end up with something like this</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb22495'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb22495','cb48016'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb22495" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> &nbsp; &nbsp;<span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">schema_id</span><span style="color: #808080;">&#41;</span>,<span style="color: #FF0000;">' '</span>,<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">'_'</span> </li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>name,<span style="color: #FF0000;">' '</span>,<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>name<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #00AF00;">sys</span>.<span style="color: #00AF00;">tables</span></li></ol></div><div id="cb48016" style="display: none; color: red;"></div></div></div>

<p><strong>We need to specify how we are connecting to SQL Server</strong><br />
You can use password and username to connect to SQL Server or you can use a trusted connections</p>




<h2>Putting it all together</h2>

<p>Here is the complete query</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb23893'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb23893','cb49170'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb23893" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'EXEC xp_cmdshell '</span><span style="color: #FF0000;">'bcp '</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AF00;">--bcp</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>+ <span style="color: #FF0000;">'.'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AF00;">--database name</span></li><li style="" class="li1">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SCHEMA_ID</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>+ <span style="color: #FF0000;">'.'</span> &nbsp;<span style="color: #00AF00;">-- schema</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>name<span style="color: #808080;">&#41;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- table</span></li><li style="" class="li1">+ <span style="color: #FF0000;">' out c:\temp\'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- output directory</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">schema_id</span><span style="color: #808080;">&#41;</span>,<span style="color: #FF0000;">' '</span>,<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">'_'</span> </li><li style="" class="li1">+ &nbsp;<span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>name,<span style="color: #FF0000;">' '</span>,<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- file name</span></li><li style="" class="li2">+ <span style="color: #FF0000;">'.txt -T -c'</span><span style="color: #FF0000;">''</span> &nbsp; <span style="color: #00AF00;">-- extension, security </span></li><li style="" class="li1"><span style="color: #0000FF;">FROM</span> <span style="color: #00AF00;">sys</span>.<span style="color: #00AF00;">tables</span></li></ol></div><div id="cb49170" style="display: none; color: red;"></div></div></div>

<p>Running that query will give you something like the following</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb83404'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb83404','cb74630'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb83404" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[Production].[ScrapReason] out c:\temp\Production_ScrapReason.txt -T -c'</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[HumanResources].[Shift] out c:\temp\HumanResources_Shift.txt -T -c'</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[Production].[ProductCategory] out c:\temp\Production_ProductCategory.txt -T -c'</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[Purchasing].[ShipMethod] out c:\temp\Purchasing_ShipMethod.txt -T -c'</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[Production].[ProductCostHistory] out c:\temp\Production_ProductCostHistory.txt -T -c'</span></li></ol></div><div id="cb74630" style="display: none; color: red;"></div></div></div>


<p>You can now take that and run it. When you run it, you will see the following output</p>

<p>NULL<br />
Starting copy...<br />
NULL<br />
32 rows copied.<br />
Network packet size (bytes): 4096<br />
Clock Time (ms.) Total     : 1      Average : (32000.00 rows per sec.)<br />
NULL</p>

<p>Sometines you don't want to see that output,In that case we need to <a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/supressing-xp_cmdshell-output">suppress xp_cmdshell output</a>, you do this by adding ,no_output at the end</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb164'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb164','cb18889'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb164" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'EXEC xp_cmdshell '</span><span style="color: #FF0000;">'bcp '</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AF00;">--bcp</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>+ <span style="color: #FF0000;">'.'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AF00;">--database name</span></li><li style="" class="li1">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SCHEMA_ID</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>+ <span style="color: #FF0000;">'.'</span> &nbsp;<span style="color: #00AF00;">-- schema</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>name<span style="color: #808080;">&#41;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- table</span></li><li style="" class="li1">+ <span style="color: #FF0000;">' out c:\temp\'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- output directory</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">schema_id</span><span style="color: #808080;">&#41;</span>,<span style="color: #FF0000;">' '</span>,<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">'_'</span> </li><li style="" class="li1">+ &nbsp;<span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>name,<span style="color: #FF0000;">' '</span>,<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- file name</span></li><li style="" class="li2">+ <span style="color: #FF0000;">'.txt -T -c'</span><span style="color: #FF0000;">',no_output'</span> &nbsp; <span style="color: #00AF00;">-- extension, security, no output </span></li><li style="" class="li1"><span style="color: #0000FF;">FROM</span> <span style="color: #00AF00;">sys</span>.<span style="color: #00AF00;">tables</span></li></ol></div><div id="cb18889" style="display: none; color: red;"></div></div></div>


<p>Now you get something like the following</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb96376'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb96376','cb13577'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb96376" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[Production].[ScrapReason] out c:\temp\Production_ScrapReason.txt -T -c'</span>,no_output</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[HumanResources].[Shift] out c:\temp\HumanResources_Shift.txt -T -c'</span>,no_output</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[Production].[ProductCategory] out c:\temp\Production_ProductCategory.txt -T -c'</span>,no_output</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">xp_cmdshell</span> <span style="color: #FF0000;">'bcp [AdventureWorks2012].[Purchasing].[ShipMethod] out c:\temp\Purchasing_ShipMethod.txt -T -c'</span>,no_output</li></ol></div><div id="cb13577" style="display: none; color: red;"></div></div></div>

<p>There you have it, a quick and dirty version to dump all the tables into files.</p>

<p>You can of course enhance this by creating a proc where you can specify only a certain schema, delimiters, how to connect etc etc</p>

<p>If you don't want to use xp_cmdshell, you can also dump the results without the xp_cmdshell part into a BAT file and call it from DOS or PowerShell</p>

<p>That query would look like this</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb21032'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb21032','cb71322'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb21032" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'bcp '</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AF00;">--bcp</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>+ <span style="color: #FF0000;">'.'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AF00;">--database name</span></li><li style="" class="li1">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SCHEMA_ID</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>+ <span style="color: #FF0000;">'.'</span> &nbsp;<span style="color: #00AF00;">-- schema</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>name<span style="color: #808080;">&#41;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- table</span></li><li style="" class="li1">+ <span style="color: #FF0000;">' out c:\temp\'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- output directory</span></li><li style="" class="li2">+ &nbsp;<span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">schema_id</span><span style="color: #808080;">&#41;</span>,<span style="color: #FF0000;">' '</span>,<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">'_'</span> </li><li style="" class="li1">+ &nbsp;<span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>name,<span style="color: #FF0000;">' '</span>,<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00AF00;">-- file name</span></li><li style="" class="li2">+ <span style="color: #FF0000;">'.txt -T -c'</span> &nbsp; <span style="color: #00AF00;">-- extension, security, </span></li><li style="" class="li1"><span style="color: #0000FF;">FROM</span> <span style="color: #00AF00;">sys</span>.<span style="color: #00AF00;">tables</span></li></ol></div><div id="cb71322" style="display: none; color: red;"></div></div></div><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/bcp-all-tables-into-files">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/bcp-all-tables-into-files#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2168</wfw:commentRss>
		</item>
				<item>
			<title>Messing with your friendly DBA on April Fools' Day</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/messing-with-your-friendly-dba</link>
			<pubDate>Fri, 29 Mar 2013 10:27:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">2167@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;April Fools&#039; Day is a day when people play practical jokes and hoaxes on each other. Why not trying to play some practical jokes on your friendly DBA  :-)&lt;/p&gt;

&lt;p&gt;The first thing we are going to do is to spoof the host and program name. This is easy to do. Click on Connect, choose Database Engine, you will see the following box&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools1.PNG?mtime=1364551429&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools1.PNG?mtime=1364551429&quot; width=&quot;411&quot; height=&quot;301&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Click on options &gt;&gt;&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools2.PNG?mtime=1364551448&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools2.PNG?mtime=1364551448&quot; width=&quot;420&quot; height=&quot;485&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Click on the Additional Connection Parameters tab and paste in the following&lt;/p&gt;

&lt;p&gt;Application Name=TOAD;Workstation ID=LarryEllison-PC&lt;/p&gt;

&lt;p&gt;Now you can verify that what you have entered is returned from SQL Server&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb31305&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;host_name&lt;/span&gt;,&lt;span style=&quot;color: #FF00FF;&quot;&gt;program_name&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #00AF00;&quot;&gt;dm_exec_sessions&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;WHERE&lt;/span&gt; session_id = &lt;span style=&quot;color: #FF00FF;&quot;&gt;@@spid&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb20405&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;pre&gt;host_name	    program_name
LarryEllison-PC	    TOAD&lt;/pre&gt;


&lt;p&gt;If the DBA monitors the connection he might notice.....if not, time for plan B&lt;/p&gt;
&lt;h2&gt;Kick it up a notch....or two&lt;/h2&gt;
&lt;p&gt;Time to become real evil  :-)&lt;br /&gt;
Find out what the biggest table is in your company. Create a database with the same name on your local instance and also create the same table. Now it is time to create a panic.&lt;br /&gt;
Open another connect dialog box, add the real server in the Server Name box, for example I entered PDW\SQLServer2015&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools3.PNG?mtime=1364551852&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools3.PNG?mtime=1364551852&quot; width=&quot;413&quot; height=&quot;306&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Click on options &gt;&gt;, click on the Additional Connection Parameters tab and paste in the following &lt;em&gt;&lt;strong&gt;Data Source=localhost&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Just to verify, run the following query&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb2400&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;@@SERVERNAME&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb30869&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That returns you the local servername. Look what you see everywhere else (highlighted in yellow)&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools4.PNG?mtime=1364552737&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools4.PNG?mtime=1364552737&quot; width=&quot;713&quot; height=&quot;440&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;I see PDW\SQLServer2015 everywhere else.&lt;br /&gt;
Now run your query which returns 0 rows&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb1470&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; HugeTable&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb43028&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Call your DBA to stop by and then ask him if he deleted all 3 billion rows from this table? Look at his face..let him run &lt;code&gt;sp_spaceused &#039;HugeTable&#039;&lt;/code&gt;. Once the panic sets in tell him he has be pranked.......&lt;/p&gt;

&lt;p&gt;Of course there is a chance that all your permissions will be taken away.....&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/messing-with-your-friendly-dba&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>April Fools' Day is a day when people play practical jokes and hoaxes on each other. Why not trying to play some practical jokes on your friendly DBA  :-)</p>

<p>The first thing we are going to do is to spoof the host and program name. This is easy to do. Click on Connect, choose Database Engine, you will see the following box</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools1.PNG?mtime=1364551429"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools1.PNG?mtime=1364551429" width="411" height="301" /></a></div>
<p>Click on options >></p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools2.PNG?mtime=1364551448"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools2.PNG?mtime=1364551448" width="420" height="485" /></a></div>
<p>Click on the Additional Connection Parameters tab and paste in the following</p>

<p>Application Name=TOAD;Workstation ID=LarryEllison-PC</p>

<p>Now you can verify that what you have entered is returned from SQL Server</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb1413'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb1413','cb3966'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb1413" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">host_name</span>,<span style="color: #FF00FF;">program_name</span> </li><li style="" class="li2"><span style="color: #0000FF;">FROM</span> &nbsp;<span style="color: #00AF00;">sys</span>.<span style="color: #00AF00;">dm_exec_sessions</span></li><li style="" class="li1"><span style="color: #0000FF;">WHERE</span> session_id = <span style="color: #FF00FF;">@@spid</span></li></ol></div><div id="cb3966" style="display: none; color: red;"></div></div></div>

<p><br /></p>
<pre>host_name	    program_name
LarryEllison-PC	    TOAD</pre>


<p>If the DBA monitors the connection he might notice.....if not, time for plan B</p>
<h2>Kick it up a notch....or two</h2>
<p>Time to become real evil  :-)<br />
Find out what the biggest table is in your company. Create a database with the same name on your local instance and also create the same table. Now it is time to create a panic.<br />
Open another connect dialog box, add the real server in the Server Name box, for example I entered PDW\SQLServer2015</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools3.PNG?mtime=1364551852"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools3.PNG?mtime=1364551852" width="413" height="306" /></a></div>

<p>Click on options >>, click on the Additional Connection Parameters tab and paste in the following <em><strong>Data Source=localhost</strong></em></p>

<p>Just to verify, run the following query</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb40044'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb40044','cb29771'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb40044" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">@@SERVERNAME</span></li></ol></div><div id="cb29771" style="display: none; color: red;"></div></div></div>

<p>That returns you the local servername. Look what you see everywhere else (highlighted in yellow)</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools4.PNG?mtime=1364552737"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/AprilFools4.PNG?mtime=1364552737" width="713" height="440" /></a></div>
<p>I see PDW\SQLServer2015 everywhere else.<br />
Now run your query which returns 0 rows</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb81883'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb81883','cb82976'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb81883" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> * <span style="color: #0000FF;">FROM</span> HugeTable</li></ol></div><div id="cb82976" style="display: none; color: red;"></div></div></div>

<p>Call your DBA to stop by and then ask him if he deleted all 3 billion rows from this table? Look at his face..let him run <code>sp_spaceused 'HugeTable'</code>. Once the panic sets in tell him he has be pranked.......</p>

<p>Of course there is a chance that all your permissions will be taken away.....</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/messing-with-your-friendly-dba">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/messing-with-your-friendly-dba#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2167</wfw:commentRss>
		</item>
				<item>
			<title>Little used SSIS tasks: Data Profiling Task</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/ssis/little-used-ssis-tasks-data</link>
			<pubDate>Thu, 28 Mar 2013 12:19:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="alt">Microsoft SQL Server Admin</category>
<category domain="alt">Microsoft SQL Server</category>
<category domain="main">SSIS</category>
<category domain="alt">Business Intelligence</category>			<guid isPermaLink="false">2166@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;I was in New York City yesterday, hanging out with fellow MVP and blogger Ted Krueger in Union Square. I asked him if he uses the Data Profiling Task task a lot, he said not really. I don&#039;t use it a lot either but I decided to show you what you can do with it.&lt;br /&gt;
When you do a lot of ETL type of work it is good to know what kind of data distribution you have, you might want to know how many NULLs you have, the statistics and more.&lt;/p&gt;

&lt;p&gt;In order to use the  Data Profiling Task in SSIS you need to do a couple of things. First thing you have to do is adding a connection, I decided to use my local machine. Next drop a Data Profiling Task on the Control Flow designer pane.&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task1.PNG?mtime=1364472826&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task1.PNG?mtime=1364472826&quot; width=&quot;173&quot; height=&quot;73&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Once you do that you will see a red circle with an x, if you hover over this icon, you will see the following text: &lt;em&gt;The &quot;Destination&quot; property is invalid: Missing destination for profile output.&lt;/em&gt; Double click on the Data Profiling Task, leave DestinationType as FileConnection, click on Destination, in the pop up window, choose New File from the Usage Type option, navigate to the folder where you want the file and give the file a name.&lt;/p&gt;

&lt;p&gt;Next we have to look what profile requests we want to include. Here is what is available according to Books On Line&lt;/p&gt;
&lt;div class=&quot;tables&quot;&gt;
&lt;table&gt;&lt;tr&gt;&lt;th&gt;&lt;p&gt;Profiles that analyze individual columns&lt;/p&gt;&lt;/th&gt;&lt;th&gt;&lt;p&gt;Description&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;Column Length Distribution Profile&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Reports all the distinct lengths of string values in the selected column and the percentage of rows in the table that each length represents.&lt;/p&gt;&lt;p&gt;This profile helps you identify problems in your data, such as values that are not valid. For example, you profile a column of United States state codes that should be two characters and discover values longer than two characters.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;Column Null Ratio Profile&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Reports the percentage of null values in the selected column.&lt;/p&gt;&lt;p&gt;This profile helps you identify problems in your data, such as an unexpectedly high ratio of null values in a column. For example, you profile a Zip Code/Postal Code column and discover an unacceptably high percentage of missing codes.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;Column Pattern Profile&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Reports a set of regular expressions that cover the specified percentage of values in a string column.&lt;/p&gt;&lt;p&gt;This profile helps you identify problems in your data, such as string that are not valid. This profile can also suggest regular expressions that can be used in the future to validate new values. For example, a pattern profile of a United States Zip Code column might produce the regular expressions: \d{5}-\d{4}, \d{5}, and \d{9}. If you see other regular expressions, your data likely contains values that are not valid or in an incorrect format.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;Column Statistics Profile&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Reports statistics, such as minimum, maximum, average, and standard deviation for numeric columns, and minimum and maximum for &lt;span&gt;&lt;span class=&quot;input&quot;&gt;datetime&lt;/span&gt;&lt;/span&gt; columns.&lt;/p&gt;&lt;p&gt;This profile helps you identify problems in your data, such as dates that are not valid. For example, you profile a column of historical dates and discover a maximum date that is in the future.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;Column Value Distribution Profile&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Reports all the distinct values in the selected column and the percentage of rows in the table that each value represents. Can also report values that represent more than a specified percentage of rows in the table.&lt;/p&gt;&lt;p&gt;This profile helps you identify problems in your data, such as an incorrect number of distinct values in a column. For example, you profile a column that is supposed to contain states in the United States and discover more than 50 distinct values.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;The following three profiles analyze multiple columns or relationships between columns and tables.&lt;/p&gt;&lt;div class=&quot;caption&quot;&gt;&lt;/div&gt;&lt;div class=&quot;tables&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;&lt;p&gt;Profiles that analyze multiple columns&lt;/p&gt;&lt;/th&gt;&lt;th&gt;&lt;p&gt;Description&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;Candidate Key Profile&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Reports whether a column or set of columns is a key, or an approximate key, for the selected table.&lt;/p&gt;&lt;p&gt;This profile also helps you identify problems in your data, such as duplicate values in a potential key column.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;Functional Dependency Profile&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Reports the extent to which the values in one column (the dependent column) depend on the values in another column or set of columns (the determinant column).&lt;/p&gt;&lt;p&gt;This profile also helps you identify problems in your data, such as values that are not valid. For example, you profile the dependency between a column that contains United States Zip Codes and a column that contains states in the United States. The same Zip Code should always have the same state, but the profile discovers violations of this dependency.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;Value Inclusion Profile&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Computes the overlap in the values between two columns or sets of columns. This profile can determine whether a column or set of columns is appropriate to serve as a foreign key between the selected tables.&lt;/p&gt;&lt;p&gt;This profile also helps you identify problems in your data, such as values that are not valid. For example, you profile the ProductID column of a Sales table and discover that the column contains values that are not found in the ProductID column of the Products table.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;I decided to pick a handful of requests. Here is what it looks like.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task3.PNG?mtime=1364472845&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task3.PNG?mtime=1364472845&quot; width=&quot;716&quot; height=&quot;615&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;As you can see, you need to specify the connection, the table as well as the columns&lt;br /&gt;
After you hit okay, run your SSIS package&lt;br /&gt;
In order to see what the task generated, you need to use the Data Profile Viewer. You can find it under SQL Server, Integration Services. &lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task4.PNG?mtime=1364472855&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task4.PNG?mtime=1364472855&quot; width=&quot;234&quot; height=&quot;208&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Run the tool, click on open and navigate to the file that the  Data Profiling Task created. Now you will see something like this&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task5.PNG?mtime=1364472864&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task5.PNG?mtime=1364472864&quot; width=&quot;887&quot; height=&quot;629&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;As you can see you get the percentage of NULL values as well as some graphical indication of the distribution.&lt;/p&gt;

What do you think, useful or do you prefer writing your own queries?&lt;/div&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/ssis/little-used-ssis-tasks-data&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>I was in New York City yesterday, hanging out with fellow MVP and blogger Ted Krueger in Union Square. I asked him if he uses the Data Profiling Task task a lot, he said not really. I don't use it a lot either but I decided to show you what you can do with it.<br />
When you do a lot of ETL type of work it is good to know what kind of data distribution you have, you might want to know how many NULLs you have, the statistics and more.</p>

<p>In order to use the  Data Profiling Task in SSIS you need to do a couple of things. First thing you have to do is adding a connection, I decided to use my local machine. Next drop a Data Profiling Task on the Control Flow designer pane.</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task1.PNG?mtime=1364472826"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task1.PNG?mtime=1364472826" width="173" height="73" /></a></div>

<p>Once you do that you will see a red circle with an x, if you hover over this icon, you will see the following text: <em>The "Destination" property is invalid: Missing destination for profile output.</em> Double click on the Data Profiling Task, leave DestinationType as FileConnection, click on Destination, in the pop up window, choose New File from the Usage Type option, navigate to the folder where you want the file and give the file a name.</p>

<p>Next we have to look what profile requests we want to include. Here is what is available according to Books On Line</p>
<div class="tables">
<table><tr><th><p>Profiles that analyze individual columns</p></th><th><p>Description</p></th></tr><tr><td><p>Column Length Distribution Profile</p></td><td><p>Reports all the distinct lengths of string values in the selected column and the percentage of rows in the table that each length represents.</p><p>This profile helps you identify problems in your data, such as values that are not valid. For example, you profile a column of United States state codes that should be two characters and discover values longer than two characters.</p></td></tr><tr><td><p>Column Null Ratio Profile</p></td><td><p>Reports the percentage of null values in the selected column.</p><p>This profile helps you identify problems in your data, such as an unexpectedly high ratio of null values in a column. For example, you profile a Zip Code/Postal Code column and discover an unacceptably high percentage of missing codes.</p></td></tr><tr><td><p>Column Pattern Profile</p></td><td><p>Reports a set of regular expressions that cover the specified percentage of values in a string column.</p><p>This profile helps you identify problems in your data, such as string that are not valid. This profile can also suggest regular expressions that can be used in the future to validate new values. For example, a pattern profile of a United States Zip Code column might produce the regular expressions: \d{5}-\d{4}, \d{5}, and \d{9}. If you see other regular expressions, your data likely contains values that are not valid or in an incorrect format.</p></td></tr><tr><td><p>Column Statistics Profile</p></td><td><p>Reports statistics, such as minimum, maximum, average, and standard deviation for numeric columns, and minimum and maximum for <span><span class="input">datetime</span></span> columns.</p><p>This profile helps you identify problems in your data, such as dates that are not valid. For example, you profile a column of historical dates and discover a maximum date that is in the future.</p></td></tr><tr><td><p>Column Value Distribution Profile</p></td><td><p>Reports all the distinct values in the selected column and the percentage of rows in the table that each value represents. Can also report values that represent more than a specified percentage of rows in the table.</p><p>This profile helps you identify problems in your data, such as an incorrect number of distinct values in a column. For example, you profile a column that is supposed to contain states in the United States and discover more than 50 distinct values.</p></td></tr></table></div><p>The following three profiles analyze multiple columns or relationships between columns and tables.</p><div class="caption"></div><div class="tables"><table><tr><th><p>Profiles that analyze multiple columns</p></th><th><p>Description</p></th></tr><tr><td><p>Candidate Key Profile</p></td><td><p>Reports whether a column or set of columns is a key, or an approximate key, for the selected table.</p><p>This profile also helps you identify problems in your data, such as duplicate values in a potential key column.</p></td></tr><tr><td><p>Functional Dependency Profile</p></td><td><p>Reports the extent to which the values in one column (the dependent column) depend on the values in another column or set of columns (the determinant column).</p><p>This profile also helps you identify problems in your data, such as values that are not valid. For example, you profile the dependency between a column that contains United States Zip Codes and a column that contains states in the United States. The same Zip Code should always have the same state, but the profile discovers violations of this dependency.</p></td></tr><tr><td><p>Value Inclusion Profile</p></td><td><p>Computes the overlap in the values between two columns or sets of columns. This profile can determine whether a column or set of columns is appropriate to serve as a foreign key between the selected tables.</p><p>This profile also helps you identify problems in your data, such as values that are not valid. For example, you profile the ProductID column of a Sales table and discover that the column contains values that are not found in the ProductID column of the Products table.</p></td></tr></table>

<p>I decided to pick a handful of requests. Here is what it looks like.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task3.PNG?mtime=1364472845"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task3.PNG?mtime=1364472845" width="716" height="615" /></a></div>

<p>As you can see, you need to specify the connection, the table as well as the columns<br />
After you hit okay, run your SSIS package<br />
In order to see what the task generated, you need to use the Data Profile Viewer. You can find it under SQL Server, Integration Services. </p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task4.PNG?mtime=1364472855"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task4.PNG?mtime=1364472855" width="234" height="208" /></a></div>
<p>Run the tool, click on open and navigate to the file that the  Data Profiling Task created. Now you will see something like this</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task5.PNG?mtime=1364472864"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/SQL2013/Data Profiling Task5.PNG?mtime=1364472864" width="887" height="629" /></a></div>
<p>As you can see you get the percentage of NULL values as well as some graphical indication of the distribution.</p>

What do you think, useful or do you prefer writing your own queries?</div><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/ssis/little-used-ssis-tasks-data">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/ssis/little-used-ssis-tasks-data#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2166</wfw:commentRss>
		</item>
				<item>
			<title>Bring SQL Server databases Online or Offline when running on Amazon RDS</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/bring-sql-server-databases-online</link>
			<pubDate>Fri, 22 Mar 2013 10:25:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="alt">Database Administration</category>
<category domain="main">Microsoft SQL Server Admin</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">2160@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;To bring a SQL Server database online or offline you can use a command like the following if your database is named test.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb17813&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;ALTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;DATABASE&lt;/span&gt; test &lt;span style=&quot;color: #0000FF;&quot;&gt;SET&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;OFFLINE&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;ALTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;DATABASE&lt;/span&gt; test &lt;span style=&quot;color: #0000FF;&quot;&gt;SET&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;ONLINE&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb18540&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When running SQL Server on Amazon&#039;s Relational Database Service it is done a little different. While you can use the command above to take the database offline, you can&#039;t use the command to bring the database online.&lt;/p&gt;

&lt;p&gt;I you have a database name test and you execute the following it will work&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb14098&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;ALTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;DATABASE&lt;/span&gt; test &lt;span style=&quot;color: #0000FF;&quot;&gt;SET&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;OFFLINE&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb41251&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can verify this by running the following&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb34295&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;USE&lt;/span&gt; test&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb60467&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You get the following error&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Msg 942, Level 14, State 4, Line 1&lt;br /&gt;
Database &#039;test&#039; cannot be opened because it is offline.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you try running the following command to bring the database online&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb20679&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;ALTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;DATABASE&lt;/span&gt; test &lt;span style=&quot;color: #0000FF;&quot;&gt;SET&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;ONLINE&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb18165&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now you get this error&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Msg 5011, Level 14, State 9, Line 1&lt;br /&gt;
User does not have permission to alter database &#039;test&#039;, the database does not exist, or the database is not in a state that allows access checks.&lt;br /&gt;
Msg 5069, Level 16, State 1, Line 1&lt;br /&gt;
ALTER DATABASE statement failed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So what can you do? RDS has a special stored procedure that will bring the databse online, the name of this stored procedure is &lt;code&gt;rdsadmin.dbo.rds_set_database_online&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here is how you use it&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb66600&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; rdsadmin.&lt;span style=&quot;color: #202020;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;rds_set_database_online&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;test&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb43610&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now you can use the test database again&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb33923&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;USE&lt;/span&gt; test&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb98228&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;See, simple, you just have to be aware of these differences&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/bring-sql-server-databases-online&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>To bring a SQL Server database online or offline you can use a command like the following if your database is named test.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb11291'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb11291','cb76336'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb11291" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> test <span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">OFFLINE</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> test <span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">ONLINE</span>;</li></ol></div><div id="cb76336" style="display: none; color: red;"></div></div></div>

<p>When running SQL Server on Amazon's Relational Database Service it is done a little different. While you can use the command above to take the database offline, you can't use the command to bring the database online.</p>

<p>I you have a database name test and you execute the following it will work</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb78232'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb78232','cb33913'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb78232" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> test <span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">OFFLINE</span></li></ol></div><div id="cb33913" style="display: none; color: red;"></div></div></div>

<p>You can verify this by running the following</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb30714'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb30714','cb18004'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb30714" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">USE</span> test</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb18004" style="display: none; color: red;"></div></div></div>

<p>You get the following error</p>

<p><em>Msg 942, Level 14, State 4, Line 1<br />
Database 'test' cannot be opened because it is offline.</em></p>

<p>If you try running the following command to bring the database online</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb78097'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb78097','cb26950'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb78097" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> test <span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">ONLINE</span>;</li></ol></div><div id="cb26950" style="display: none; color: red;"></div></div></div>

<p>Now you get this error</p>

<p><em>Msg 5011, Level 14, State 9, Line 1<br />
User does not have permission to alter database 'test', the database does not exist, or the database is not in a state that allows access checks.<br />
Msg 5069, Level 16, State 1, Line 1<br />
ALTER DATABASE statement failed.</em></p>

<p>So what can you do? RDS has a special stored procedure that will bring the databse online, the name of this stored procedure is <code>rdsadmin.dbo.rds_set_database_online</code></p>

<p>Here is how you use it</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb36358'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb36358','cb38787'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb36358" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> rdsadmin.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">rds_set_database_online</span> &nbsp;<span style="color: #FF0000;">'test'</span></li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb38787" style="display: none; color: red;"></div></div></div>

<p>Now you can use the test database again</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb92647'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb92647','cb85304'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb92647" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">USE</span> test</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb85304" style="display: none; color: red;"></div></div></div>

<p>See, simple, you just have to be aware of these differences</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/bring-sql-server-databases-online">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/bring-sql-server-databases-online#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2160</wfw:commentRss>
		</item>
				<item>
			<title>Turning on Optimize for Ad hoc Workloads, Ad Hoc Distributed Queries and more on a AWS RDS SQL Server Instance</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/turning-on-optimize-for-ad</link>
			<pubDate>Thu, 21 Mar 2013 15:39:00 +0000</pubDate>			<dc:creator>SQLDenis</dc:creator>
			<category domain="alt">Database Administration</category>
<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">2159@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;There are several advanced options that you can modify in SQL Server. If you want to turn on optimize for ad hoc workloads in SQL Server, you can run the following script&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb83966&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #AF0000;&quot;&gt;sp_configure&lt;/span&gt; N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;optimize for ad hoc workloads&#039;&lt;/span&gt;, N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;1&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;RECONFIGURE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;WITH&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;OVERRIDE&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb31126&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;If you want to use OPENROWSET, you can run the following&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb9336&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXECUTE&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;sys&lt;/span&gt;.&lt;span style=&quot;color: #AF0000;&quot;&gt;sp_configure&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;Ad Hoc Distributed Queries&#039;&lt;/span&gt;, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;1&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;RECONFIGURE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;WITH&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;OVERRIDE&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb93718&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When running SQL Server on Amazon&#039;s AWS RDS, you can&#039;t do it like that. If you try running it, you will get the following error.&lt;/p&gt;

&lt;p&gt;Msg 15247, Level 16, State 1, Procedure sp_configure, Line 105&lt;br /&gt;
User does not have permission to perform this action.&lt;br /&gt;
Msg 5812, Level 14, State 1, Line 1&lt;br /&gt;
You do not have permission to run the RECONFIGURE statement.&lt;/p&gt;


&lt;p&gt;Here is how you have to do it. From the dashboard click on &lt;em&gt;DB Parameter Groups&lt;/em&gt;. Click on Create DB Parameter Group, pick the version of SQL Server and fill in the text boxes. Here is what it looks like&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup1.PNG?mtime=1363879041&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup1.PNG?mtime=1363879041&quot; width=&quot;824&quot; height=&quot;207&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Check the DB Parameter Group you just created and click on Edit Parameters&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup2.PNG?mtime=1363879237&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup2.PNG?mtime=1363879237&quot; width=&quot;740&quot; height=&quot;180&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;You will see a screen like this pop up&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup3.PNG?mtime=1363879348&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup3.PNG?mtime=1363879348&quot; width=&quot;617&quot; height=&quot;529&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Modify the ones that you are interested in and click Save Changes&lt;/p&gt;

&lt;p&gt;Click on DB Instances, Click on the Instance Actions dropdown &lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup4.PNG?mtime=1363879526&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup4.PNG?mtime=1363879526&quot; width=&quot;357&quot; height=&quot;225&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Select Modify from this dropdown&lt;/p&gt;

&lt;p&gt;You will see a screen like this&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup5.PNG?mtime=1363879698&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup5.PNG?mtime=1363879698&quot; width=&quot;654&quot; height=&quot;387&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;In the Parameter Group dropdown, pick the Parameter Group you just created, hit Continue and then Modify DB Instance.&lt;br /&gt;
In order for this to take effect, you need to reboot your instance&lt;br /&gt;
Click on DB Instances, click on the Instance Actions dropdown &lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup4.PNG?mtime=1363879526&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup4.PNG?mtime=1363879526&quot; width=&quot;357&quot; height=&quot;225&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Select reboot from this dropdown&lt;/p&gt;

&lt;p&gt;Once the instance is available again, connect from SSMS, right click on the Server, select Properties and click on the Advanced page. It should now match what you have edited in the DB Parameters Group&lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup6.PNG?mtime=1363880116&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup6.PNG?mtime=1363880116&quot; width=&quot;474&quot; height=&quot;335&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;That is it for this post, as you can see it is pretty simple to do&lt;br /&gt;
Also check out my other AWS RDS SQL Server posts: &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/trying-out-amazon-relational-database&quot;&gt;Trying out Amazon Relational Database Service&lt;/a&gt; and &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/how-to-read-the-error&quot;&gt;How to read the error log on an Amazon RDS SQL Server instance&lt;/a&gt;&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/turning-on-optimize-for-ad&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>There are several advanced options that you can modify in SQL Server. If you want to turn on optimize for ad hoc workloads in SQL Server, you can run the following script</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb55335'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb55335','cb99267'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb55335" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> <span style="color: #00AF00;">sys</span>.<span style="color: #AF0000;">sp_configure</span> N<span style="color: #FF0000;">'optimize for ad hoc workloads'</span>, N<span style="color: #FF0000;">'1'</span></li><li style="" class="li2"><span style="color: #0000FF;">RECONFIGURE</span> <span style="color: #0000FF;">WITH</span> <span style="color: #0000FF;">OVERRIDE</span></li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb99267" style="display: none; color: red;"></div></div></div>


<p>If you want to use OPENROWSET, you can run the following</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb56786'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb56786','cb80887'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb56786" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">EXECUTE</span> <span style="color: #00AF00;">sys</span>.<span style="color: #AF0000;">sp_configure</span><span style="color: #FF0000;">'Ad Hoc Distributed Queries'</span>, <span style="color: #FF0000;">'1'</span></li><li style="" class="li2"><span style="color: #0000FF;">RECONFIGURE</span> <span style="color: #0000FF;">WITH</span> <span style="color: #0000FF;">OVERRIDE</span></li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb80887" style="display: none; color: red;"></div></div></div>

<p>When running SQL Server on Amazon's AWS RDS, you can't do it like that. If you try running it, you will get the following error.</p>

<p>Msg 15247, Level 16, State 1, Procedure sp_configure, Line 105<br />
User does not have permission to perform this action.<br />
Msg 5812, Level 14, State 1, Line 1<br />
You do not have permission to run the RECONFIGURE statement.</p>


<p>Here is how you have to do it. From the dashboard click on <em>DB Parameter Groups</em>. Click on Create DB Parameter Group, pick the version of SQL Server and fill in the text boxes. Here is what it looks like</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup1.PNG?mtime=1363879041"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup1.PNG?mtime=1363879041" width="824" height="207" /></a></div>

<p>Check the DB Parameter Group you just created and click on Edit Parameters</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup2.PNG?mtime=1363879237"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup2.PNG?mtime=1363879237" width="740" height="180" /></a></div>

<p>You will see a screen like this pop up</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup3.PNG?mtime=1363879348"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup3.PNG?mtime=1363879348" width="617" height="529" /></a></div>
<p>Modify the ones that you are interested in and click Save Changes</p>

<p>Click on DB Instances, Click on the Instance Actions dropdown </p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup4.PNG?mtime=1363879526"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup4.PNG?mtime=1363879526" width="357" height="225" /></a></div>
<p>Select Modify from this dropdown</p>

<p>You will see a screen like this</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup5.PNG?mtime=1363879698"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup5.PNG?mtime=1363879698" width="654" height="387" /></a></div>

<p>In the Parameter Group dropdown, pick the Parameter Group you just created, hit Continue and then Modify DB Instance.<br />
In order for this to take effect, you need to reboot your instance<br />
Click on DB Instances, click on the Instance Actions dropdown </p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup4.PNG?mtime=1363879526"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup4.PNG?mtime=1363879526" width="357" height="225" /></a></div>
<p>Select reboot from this dropdown</p>

<p>Once the instance is available again, connect from SSMS, right click on the Server, select Properties and click on the Advanced page. It should now match what you have edited in the DB Parameters Group</p>
<div class="image_block"><a href="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup6.PNG?mtime=1363880116"><img alt="" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/Denis/AWS/DBParameterGroup6.PNG?mtime=1363880116" width="474" height="335" /></a></div>

<p>That is it for this post, as you can see it is pretty simple to do<br />
Also check out my other AWS RDS SQL Server posts: <a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/trying-out-amazon-relational-database">Trying out Amazon Relational Database Service</a> and <a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/how-to-read-the-error">How to read the error log on an Amazon RDS SQL Server instance</a></p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/turning-on-optimize-for-ad">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/turning-on-optimize-for-ad#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2159</wfw:commentRss>
		</item>
			</channel>
</rss>
