<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>SQL Yoga</title>
	<atom:link href="http://tejasnshah.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://tejasnshah.wordpress.com</link>
	<description></description>
	<lastBuildDate>Mon, 31 Oct 2011 07:22:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='tejasnshah.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>SQL Yoga</title>
		<link>http://tejasnshah.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://tejasnshah.wordpress.com/osd.xml" title="SQL Yoga" />
	<atom:link rel='hub' href='http://tejasnshah.wordpress.com/?pushpress=hub'/>
		<item>
		<title>SQL SERVER: Community Tech Days in our City at Ahmedabad on 3rd October 2009</title>
		<link>http://tejasnshah.wordpress.com/2009/09/15/sql-server-community-tech-days-in-our-city-at-ahmedabad-on-3rd-october-2009/</link>
		<comments>http://tejasnshah.wordpress.com/2009/09/15/sql-server-community-tech-days-in-our-city-at-ahmedabad-on-3rd-october-2009/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 10:07:00 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[CommunityTechDays]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Ahmedabad]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[TechDays]]></category>
		<category><![CDATA[Tejas Shah]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/2009/09/15/sql-server-community-tech-days-in-our-city-at-ahmedabad-on-3rd-october-2009/</guid>
		<description><![CDATA[Microsoft Community Tech Days are in 11 cities in INDIA with 19 insightful Technical Sessions. These insightful Technical sessions are available in our city “Ahmedabad”, Gujarat on 3rd October 2009. So book your calendar for this day and be a part of this TechDays. Limited seats are available , so please register yourself with this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=231&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table cellspacing="0" cellpadding="2" width="450" border="0">
<tbody>
<tr>
<td valign="top" width="448">Microsoft Community Tech Days are in 11 cities in INDIA with 19 insightful Technical Sessions.          </p>
<p>These insightful Technical sessions are available in our city <strong>“Ahmedabad”, Gujarat on 3rd October 2009.            <br /></strong>          <br />So book your calendar for this day and be a part of this TechDays.           </p>
<p>Limited seats are available , so please register yourself with this event:           </p>
<p>You can find Register link at: <a href="http://www.SQLYoga.com">http://www.SQLYoga.com</a>           </p>
<p>Let me know if you have any problem in registrations.</td>
</td>
</tr>
</tbody>
<tbody></tbody>
</table>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/231/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=231&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/09/15/sql-server-community-tech-days-in-our-city-at-ahmedabad-on-3rd-october-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER: Check if Node exists in XML or not</title>
		<link>http://tejasnshah.wordpress.com/2009/08/12/sql-server-check-if-node-exists-in-xml-or-not/</link>
		<comments>http://tejasnshah.wordpress.com/2009/08/12/sql-server-check-if-node-exists-in-xml-or-not/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 07:20:00 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XML - SQL Server]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER WITH XML]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[Tejas Shah]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/2009/08/12/sql-server-check-if-node-exists-in-xml-or-not/</guid>
		<description><![CDATA[Today, I have one requirement to check dynamically if a node exists in my xml or NOT. I have a stored procedure that receives XML and I need to check if the message information xml contains one Node or NOT. If that node exists then I need to execute that Stored Procedure by different logic [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=229&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<pre class="csharpcode"></pre>
<table cellspacing="0" cellpadding="2" width="431" border="0">
<tbody>
<tr>
<td valign="top" width="429">Today, I have one requirement to check dynamically if a node exists in my xml or NOT. </p>
<p>I have a stored procedure that receives XML and I need to check if the message information xml contains one Node or NOT. If that node exists then I need to execute that Stored Procedure by different logic and if not it should run with different logic. </p>
<p>I figure it out by using EXISTS.</p>
<p>This is my XML, that I got as parameter.
<pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:17px;background-color:#ffffff;margin:0;">DECLARE @ExportData  XML
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:17px;background-color:#ffffff;margin:0;">SELECT @ExportData =
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:16px;background-color:#ffffff;margin:0;">'<span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Data</span> <span style="color:#ff0000;">Number</span>=<span style="color:#0000ff;">"A123"</span><span style="color:#0000ff;">&gt;</span>
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:13px;background-color:#ffffff;margin:0;">  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">BulkData</span><span style="color:#0000ff;">&gt;</span>
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:13px;background-color:#ffffff;margin:0;">    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">EachData</span> <span style="color:#ff0000;">Parts</span>=<span style="color:#0000ff;">"Test1"</span> <span style="color:#0000ff;">/&gt;</span>
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:13px;background-color:#ffffff;margin:0;">    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">EachData</span> <span style="color:#ff0000;">Parts</span>=<span style="color:#0000ff;">"Test2"</span> <span style="color:#0000ff;">/&gt;</span>
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:15px;background-color:#ffffff;margin:0;">    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">EachData</span> <span style="color:#ff0000;">Parts</span>=<span style="color:#0000ff;">"Test3"</span> <span style="color:#0000ff;">/&gt;</span>
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:16px;background-color:#ffffff;margin:0;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">BulkData</span><span style="color:#0000ff;">&gt;</span>
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;height:1px;background-color:#ffffff;margin:0;"><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Data</span><span style="color:#0000ff;">&gt;</span>'
</pre>
</pre>
<p>Now I need to check if “BulkData” node exists in XML, then I need to write different logic to get the result. <br />So, I used this</p>
<pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"><a style="color:#0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=SELECT&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">SELECT</a> @ExportData.exist('<span style="color:#8b0000;">(//BulkData)</span>')</pre>
</pre>
<p>This will return “1” if node is exists else return “0”.</p>
<p>That’s it. I can write based on the return result by this statement.</p>
<p>Let me know if it helps you.</p>
<p>Reference : <strong>Tejas Shah (</strong><a href="http://www.SQLYoga.com"><strong>http://www.SQLYoga.com</strong></a><strong>)</strong></td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/229/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=229&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/08/12/sql-server-check-if-node-exists-in-xml-or-not/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER: Use CONTEXT_INFO</title>
		<link>http://tejasnshah.wordpress.com/2009/07/31/sql-server-use-context_info/</link>
		<comments>http://tejasnshah.wordpress.com/2009/07/31/sql-server-use-context_info/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 06:54:00 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[CONTEXT_INFO]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[Tejas Shah]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/2009/07/30/sql-server-use-context_info/</guid>
		<description><![CDATA[Recently I have situation where I have following situation: I don’t need to execute of trigger’s code, if it is called from particular stored procedure. If data is being updated by from any other places, like application, or any other stored procedures, trigger code should be executed. I search and I got the option CONTEXT_INFO [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=224&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table cellspacing="0" cellpadding="2" width="429" border="0">
<tbody>
<tr>
<td valign="top" width="427">
<p>Recently I have situation where I have following situation:</p>
<p>I don’t need to execute of trigger’s code, if it is called from particular stored procedure. If data is being updated by from any other places, like application, or any other stored procedures, trigger code should be executed.</p>
<p>I search and I got the option CONTEXT_INFO with SQL SERVER. Let me share this with all of you.</p>
<p>We can use value stored in CONTEXT_INFO in that session only. If there is new session we cannot use that value stored in CONTEXT_INFO.</p>
<p>We can set CONTEXT_INFO up to 128 bytes of binary information with the current session or connection.</p>
<p>Let see an example, for better understanding:</p>
<div id="codeSnippetWrapper">
<div class="csharpcode-wrapper" id="codeSnippetWrapper">
<pre class="csharpcode"><span class="kwrd">CREATE</span> <span class="kwrd">TABLE</span> tblA(ID <span class="kwrd">INT</span> <span class="kwrd">IDENTITY</span>,ColVal <span class="kwrd">VARCHAR</span>(100))Let’s create two SPs, which will insert a record into tblA, which is just created</pre>
</p></div>
</p></div>
<div class="csharpcode-wrapper" id="codeSnippetWrapper">
<pre class="csharpcode"><span class="kwrd">CREATE</span> <span class="kwrd">PROC</span> TestA<span class="kwrd">AS</span><span class="kwrd">BEGIN</span>     INSERT <span class="kwrd">INTO</span> tblA(ColVal)    <span class="kwrd">SELECT</span> <span class="str">'Allow To insert'</span><span class="kwrd">END</span></pre>
<p></div>
<div class="csharpcode-wrapper" id="codeSnippetWrapper">
<pre class="csharpcode"><span class="kwrd">CREATE</span> <span class="kwrd">PROC</span> TestB<span class="kwrd">AS</span><span class="kwrd">BEGIN</span> 

    <span class="kwrd">DECLARE</span> @UID VARBINARY(128)    <span class="kwrd">SELECT</span> @UID = <span class="kwrd">CAST</span>(<span class="str">'TestB'</span> <span class="kwrd">AS</span> VARBINARY(128))    <span class="kwrd">SET</span> CONTEXT_INFO 0x5465737442

    INSERT <span class="kwrd">INTO</span> tblA(ColVal)    <span class="kwrd">SELECT</span> <span class="str">'Not Allow To insert'</span>

<span class="kwrd">END</span></pre>
<p></div>
<p>In this example, when we execute SP: TestA, it should allow to insert record in the table, while we execute SP: TestB, it should restrict. Here I set CONTEXT_INFO with SPName. I can use the same whatever is stored in CONTEXT_INFO during the current session.</p>
<p>To make validation as defined above, lets create one trigger to restrict/allow user to proceed.</p>
<div class="csharpcode-wrapper" id="codeSnippetWrapper">
<pre class="csharpcode"><span class="kwrd">CREATE</span> <span class="kwrd">TRIGGER</span> trg_TblA   <span class="kwrd">ON</span>  tblA   <span class="kwrd">AFTER</span> INSERT,<span class="kwrd">DELETE</span>,<span class="kwrd">UPDATE</span><span class="kwrd">AS</span> <span class="kwrd">BEGIN</span>    <span class="kwrd">SET</span> NOCOUNT <span class="kwrd">ON</span>;

    <span class="kwrd">DECLARE</span> @Message varbinary(128)    <span class="kwrd">SELECT</span> @Message = <span class="kwrd">cast</span>(<span class="str">'TestB'</span> <span class="kwrd">as</span> varbinary(128))

    <span class="kwrd">IF</span>    @Message = CONTEXT_INFO() <span class="kwrd">BEGIN</span>        <span class="kwrd">RAISERROR</span>(<span class="str">'Not Allowed to Insert/Update/Delete from SP: TestB'</span>,15,1)        <span class="kwrd">ROLLBACK</span> <span class="kwrd">TRAN</span>    <span class="kwrd">END</span>

<span class="kwrd">END</span><span class="kwrd">GO</span></pre>
<p></div>
<p>In Trigger, as you can see, I again converted the SP name and compare it with CONTEXT_INFO.</p>
<p>When Stored Procedure TestA is being executed, CONTEXT_INFO is not set, so trigger will not find comparison and allows user to insert record.</p>
<p>While we execute TestB, as we have set CONTEXT_INFO, system will find comparison in trigger and restrict us to complete transaction. So system will give error message: </p>
<p>So, by this way we can validate value in trigger, to make such decision</p>
</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=224&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/07/31/sql-server-use-context_info/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER: Reset Setup Values, when SQL SERVER is started/restarted</title>
		<link>http://tejasnshah.wordpress.com/2009/07/15/sql-server-reset-setup-values-when-sql-server-is-startedrestarted/</link>
		<comments>http://tejasnshah.wordpress.com/2009/07/15/sql-server-reset-setup-values-when-sql-server-is-startedrestarted/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 13:17:00 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL Services]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[T-SQL Syntax]]></category>
		<category><![CDATA[Tejas Shah]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/2009/07/15/sql-server-reset-setup-values-when-sql-server-is-startedrestarted/</guid>
		<description><![CDATA[We have a requirements to clear all setup values when SQL SERVER is started/restarted and we need to setup default values to setup table. I found one Stored Procedure provided by MS SQL SERVER. Let me share it with all of you. SQL SERVER provides this SP: “sp_procoption”, which is auto executed every time when [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=218&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="0" width="452">
<tbody>
<tr>
<td width="450" valign="top">We have a requirements to clear all setup values when SQL SERVER is started/restarted and we need to setup default values to setup table.</p>
<p>I found one Stored Procedure provided by MS SQL SERVER. Let me share it with all of you.</p>
<p>SQL SERVER provides this SP: “sp_procoption”, which is auto executed every time when SQL SERVER service has been started. I found this SP and it helps me to figure it out the solution for the request as following way. Let me show you how to use it</p>
<p>Syntax use this SP:</p>
<div>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#0000ff;">EXEC</span> SP_PROCOPTION
@ProcName = <span style="color:#006080;">'SPNAME'</span>,
@OptionName = <span style="color:#006080;">'startup'</span>,
@OptionValue = <span style="color:#006080;">'true/false OR on/off'</span></pre>
<p>@ProcName, should be Stored procedure name which should be executed when SQL SERVER is started. This stored procedure must be in “master” database.</p></div>
<div>@OptionName, should be “startup” always.</div>
<div></div>
<div>@OptionValue, this should be set up to execute this given sp or not. If it is “true/on”, given sp will be execute every time when SQL SERVER is started. If it is “false/off”, it will not.</div>
<div></div>
<div>That’s it, lets take an example.</div>
<div></div>
<div>I have one Database called Test, I have created setup table:</div>
<div id="codeSnippetWrapper">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#0000ff;">CREATE</span> <span style="color:#0000ff;">TABLE</span> SetupTable(
Seq <span style="color:#0000ff;">INT</span> <span style="color:#0000ff;">IDENTITY</span>,
Code <span style="color:#0000ff;">VARCHAR</span>(100)
)</pre>
<p><span style="font-family:Courier New;">Lets insert some default values to this table:</span></div>
<div id="codeSnippetWrapper">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;">INSERT <span style="color:#0000ff;">INTO</span> SetupTable <span style="color:#0000ff;">VALUES</span>(<span style="color:#006080;">'A'</span>)
INSERT <span style="color:#0000ff;">INTO</span> SetupTable <span style="color:#0000ff;">VALUES</span>(<span style="color:#006080;">'B'</span>)
INSERT <span style="color:#0000ff;">INTO</span> SetupTable <span style="color:#0000ff;">VALUES</span>(<span style="color:#006080;">'C'</span>)
INSERT <span style="color:#0000ff;">INTO</span> SetupTable <span style="color:#0000ff;">VALUES</span>(<span style="color:#006080;">'D'</span>)</pre>
<p><span style="font-family:Courier New;">What I need to do is, I need to wipe out this values when SQL SERVER is started and fill it with the same default values, because these values might be updated by application.</span><span style="font-family:Courier New;">So, I created one stored procedure in <strong>master</strong> <strong>database, </strong>named, </span></div>
<div id="codeSnippetWrapper">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#0000ff;">CREATE</span> <span style="color:#0000ff;">PROC</span> ClearAllData <span style="color:#0000ff;">AS</span>

<span style="color:#0000ff;">DELETE</span><span style="color:#0000ff;">
FROM</span>    Test.dbo.SetupTable

INSERT <span style="color:#0000ff;">INTO</span> SetupTable <span style="color:#0000ff;">VALUES</span>(<span style="color:#006080;">'X'</span>)
INSERT <span style="color:#0000ff;">INTO</span> SetupTable <span style="color:#0000ff;">VALUES</span>(<span style="color:#006080;">'Y'</span>)
INSERT <span style="color:#0000ff;">INTO</span> SetupTable <span style="color:#0000ff;">VALUES</span>(<span style="color:#006080;">'Z'</span>)</pre>
<p>and set up this stored procedure as auto executed every time when SQL SERVER is started as:</p></div>
<div>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#0000ff;">EXEC</span> SP_PROCOPTION
              @ProcName = <span style="color:#006080;">'ClearAllData'</span>,
              @OptionName = <span style="color:#006080;">'startup'</span>,
              @OptionValue = <span style="color:#006080;">'true'</span></pre>
</div>
<div>Now, restart SQL SERVICES, and you find that old values will be deleted and new values with ‘X’, ‘Y’, and ‘Z’ will be inserted automatically.</div>
<div>If now you want to stop it to execute automatically, we just need to execute this with “false” as:</div>
<div>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#0000ff;">EXEC</span> SP_PROCOPTION
               @ProcName = <span style="color:#006080;">'ClearAllData'</span>,
               @OptionName = <span style="color:#006080;">'startup'</span>,
               @OptionValue = <span style="color:#006080;">'false'</span></pre>
</div>
<div>I hope this is very clear to use this feature.</div>
<div></div>
<div>Reference : <strong>Tejas Shah (<a href="http://www.SQLYoga.com">http://www.SQLYoga.com</a>)</strong></div>
</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/218/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=218&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/07/15/sql-server-reset-setup-values-when-sql-server-is-startedrestarted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER: SQL Query To Find Table Dependencies</title>
		<link>http://tejasnshah.wordpress.com/2009/04/08/sql-server-sql-query-to-find-table-dependencies/</link>
		<comments>http://tejasnshah.wordpress.com/2009/04/08/sql-server-sql-query-to-find-table-dependencies/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 14:35:00 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Find Table Dependencies]]></category>
		<category><![CDATA[Most Used Table]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/2009/04/08/sql-server-sql-query-to-find-table-dependencies/</guid>
		<description><![CDATA[We have very large database and today we want to search the tables which are used mostly. Means tables which are used in Procedures, Constraints, Views, Triggers etc. I know this is very strange requirement, but we need to do this. So, I tried to make an query which will help me to find out [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=217&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table cellspacing="0" cellpadding="0" width="449" border="0">
<tbody>
<tr>
<td valign="top" width="447">We have very large database and today we want to search the tables which are used mostly.          </p>
<p>Means tables which are used in Procedures, Constraints, Views, Triggers etc.           </p>
<p>I know this is very strange requirement, but we need to do this.           </p>
<p>So, I tried to make an query which will help me to find out the top most tables used in other objects as I mentioned           </p>
<p>Let me share that sp with all of you:           </p>
<p>SELECT TableName, COUNT(*)            <br />FROM (             <br />Select Distinct             <br />o.Name &#8216;TableName&#8217;,             <br />op.Name &#8216;DependentObject&#8217;             <br />From SysObjects o             <br />INNER Join SysDepends d ON d.DepId = o.Id             <br />INNER Join SysObjects op on op.Id = d.Id             <br />Where o.XType = &#8216;U&#8217;             <br />Group by o.Name, o.Id, op.Name             <br />) x             <br />GROUP BY TableName             <br />ORDER BY 2 desc</p>
<p>So, I made my life easy, by using this. I can get the list if Tables which are used most.           </p>
<p>Let me know if it helps you in any way.           </p>
</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/217/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=217&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/04/08/sql-server-sql-query-to-find-table-dependencies/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SEVER: How to make an Entry in Event Viewer using SQL SERVER</title>
		<link>http://tejasnshah.wordpress.com/2009/04/02/sql-sever-how-to-make-an-entry-in-event-viewer-using-sql-server/</link>
		<comments>http://tejasnshah.wordpress.com/2009/04/02/sql-sever-how-to-make-an-entry-in-event-viewer-using-sql-server/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 09:42:27 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Event Viewer]]></category>
		<category><![CDATA[Raiserror]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Tejas Shah]]></category>
		<category><![CDATA[XP_LogEvent]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/2009/04/02/sql-sever-how-to-make-an-entry-in-event-viewer-using-sql-server/</guid>
		<description><![CDATA[Today I came across the situation where I need to following scenario. I need to make entry in Event Viewer when there is an error in Stored Procedure. I wondered to do this, but finally I come up with the solution. SQL is much powerful. SQL provides us to make an entry in Event Viewer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=213&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table cellspacing="0" cellpadding="2" width="400" border="0">
<tbody>
<tr>
<td valign="top" width="400">Today I came across the situation where I need to following scenario.          </p>
<p>I need to make entry in Event Viewer when there is an error in Stored Procedure.           </p>
<p>I wondered to do this, but finally I come up with the solution. SQL is much powerful.           </p>
<p>SQL provides us to make an entry in Event Viewer by two ways:           <br />1. using XP_LogEvent
<p>2. By Raiserror WITH LOG</p>
<p> Lets first see the way using <strong>XP_LogEvent:</strong>           </p>
<p>Here I have created one SP which will raise an error “Divide by zero error encountered.” as I tried to do “10 / 0”.           <br /> 
<p>CREATE PROCEDURE TestEventViewer            <br />AS             <br />BEGIN TRY             <br />&#160;&#160;&#160; SELECT&#160; 10/0             <br />END TRY             <br />BEGIN CATCH             <br />&#160;&#160;&#160; PRINT ERROR_Message()             <br />&#160;&#160;&#160; DECLARE @msg VARCHAR(100)             <br />&#160;&#160;&#160; SELECT @msg = ERROR_Message() </p>
<p>&#160;&#160;&#160; EXEC xp_logevent 60000, @msg, informational </p>
<p>END CATCH</p>
<p>Lets Execute this SP:</p>
<p>EXEC TestEventViewer</p>
<p>This will write entry in Event Viewer. Now open Event Viewer. You can find Event Viewer at Control Panel –&gt; Administrative Tools –&gt; Event Viewer.</p>
<p>You will get en entry of Error there.</p>
<p><a href="http://tejasnshah.files.wordpress.com/2009/04/171.jpg"><img title="171" style="display:inline;border-width:0;" height="152" alt="171" src="http://tejasnshah.files.wordpress.com/2009/04/171-thumb.jpg?w=280&#038;h=152" width="280" border="0" /></a> </p>
<p>So we can do this by Extended Stored Procedure: “xp_logevent”.</p>
<p>Let see the parameters of this Procedure.</p>
<p>First Parameter: “60000” is the Error Number</p>
<p>Second Parameter: <a href="mailto:&ldquo;@msg">“@msg</a>” is the message to be displayed in Event Viewer.</p>
<p>Third Parameter: “informational” is the Error Level. It could be “informational”, “Error”, “Warning”.</p>
<p>Now, Lets see by another way <strong>By Raiserror WITH LOG:</strong></p>
<p>It is the same way as we used Raiserror to Raise an Error.</p>
<p>CREATE PROCEDURE TestEventViewer            <br />AS             <br />BEGIN TRY             <br />&#160;&#160;&#160; SELECT&#160; 10/0             <br />END TRY             <br />BEGIN CATCH             <br />&#160;&#160;&#160; PRINT ERROR_Message()             <br />&#160;&#160;&#160; DECLARE @msg VARCHAR(100)             <br />&#160;&#160;&#160; SELECT @msg = ERROR_Message() </p>
<p>&#160;&#160;&#160; RAISERROR(@msg, 11, 1) WITH LOG</p>
<p>END CATCH </p>
<p>Lets Execute this SP: </p>
<p>EXEC TestEventViewer.</p>
<p>So By these ways we can make an entry to Event Viewer.</p>
<p>Let me know if it helps you in any way</p>
</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/213/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=213&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/04/02/sql-sever-how-to-make-an-entry-in-event-viewer-using-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>

		<media:content url="http://tejasnshah.files.wordpress.com/2009/04/171-thumb.jpg" medium="image">
			<media:title type="html">171</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER: How much space occupied by Each Table with sp_MSforeachtable procedure</title>
		<link>http://tejasnshah.wordpress.com/2009/03/26/sql-server-how-much-space-occupied-by-each-table-with-sp_msforeachtable-procedure/</link>
		<comments>http://tejasnshah.wordpress.com/2009/03/26/sql-server-how-much-space-occupied-by-each-table-with-sp_msforeachtable-procedure/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 07:34:29 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Iterate Each Table]]></category>
		<category><![CDATA[sp_MSforeachtable]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Tejas Shah]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/?p=203</guid>
		<description><![CDATA[Today, I came across requirement where I need to perform an action on all of the tables within a database. For example, How much space occupied by each table. I found undocumented Procedure: sp_MSforEachTable in the master database. The following script reports the space used and allocated for every table in the database. USE AdventureWorks; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=203&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today, I came across requirement where I need to perform an action on all of the tables within a database. </p>
<p>For example, How much space occupied by each table.</p>
<p>I found undocumented Procedure: sp_MSforEachTable in the master database.</p>
<p>The following script reports the space used and allocated for every table in the database.</p>
<p>USE AdventureWorks;<br />
EXECUTE sp_MSforeachtable &#8216;sp_spaceused [?]&#8216;</p>
<p>So, We can use sp_MSforeachtable procedure when we need to loop through each table.</p>
<p>Let me know if it helps you in any way.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/203/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=203&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/03/26/sql-server-how-much-space-occupied-by-each-table-with-sp_msforeachtable-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER: Difference between OpenQuery and OpenRowSet</title>
		<link>http://tejasnshah.wordpress.com/2009/03/25/sql-server-difference-between-openquery-and-openrowset/</link>
		<comments>http://tejasnshah.wordpress.com/2009/03/25/sql-server-difference-between-openquery-and-openrowset/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 08:07:24 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL Remote Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[OpenQuery]]></category>
		<category><![CDATA[OpenRowSet]]></category>
		<category><![CDATA[Special SQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Tejas Shah]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/?p=200</guid>
		<description><![CDATA[Today, one developer asked me what is the difference between OpenQuery and OpenRowSet. Let me share this thing with all of you. Syntax for both the command: OPENQUERY ( linked_server ,&#8217;query&#8217; ) OPENROWSET ( &#8216;provider_name&#8217; , &#8216;datasource&#8217; ; &#8216;user_id&#8217; ; &#8216;password&#8217; , { [ catalog. ] [ schema. ] object &#124; &#8216;query&#8217; } ) Difference [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=200&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today, one developer asked me what is the difference between OpenQuery and OpenRowSet.</p>
<p>Let me share this thing with all of you.</p>
<p>Syntax for both the command:</p>
<p>OPENQUERY ( linked_server ,&#8217;query&#8217; )</p>
<p>OPENROWSET<br />
(  &#8216;provider_name&#8217; ,  &#8216;datasource&#8217; ; &#8216;user_id&#8217; ; &#8216;password&#8217;<br />
  , {   [ catalog. ] [ schema. ] object | &#8216;query&#8217; }<br />
 )</p>
<p>Difference is:<br />
OpenQuery uses a predefined linked server,<br />
While OpenRowSet has to specify all the connection options. So with OpenRowSet you can query to your remote SQL server from local.</p>
<p>Else it&#8217;s the same.</p>
<p>Let me know if it helps you in any way.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=200&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/03/25/sql-server-difference-between-openquery-and-openrowset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER: Get Result ORDER BY Time regardless Date on SQL DateTime column</title>
		<link>http://tejasnshah.wordpress.com/2009/03/24/sql-server-select-result-order-by-time/</link>
		<comments>http://tejasnshah.wordpress.com/2009/03/24/sql-server-select-result-order-by-time/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 14:04:44 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[T-SQL Syntax]]></category>
		<category><![CDATA[Tejas Shah]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/?p=192</guid>
		<description><![CDATA[Usually we save Time with Dates in DATETIME column. Today, I came across situation, where I need to sort my result set by Time, regardless the Date. Let&#8217;s see Example I have some sample data like this: DECLARE @Data TABLE(dt DATETIME) INSERT INTO @Data(dt) SELECT &#8217;2008-12-05 04:00:00.000&#8242; UNION ALL SELECT &#8217;2008-12-10 10:00:00.000&#8242; UNION ALL SELECT &#8217;2009-03-01 08:00:00.000&#8242; UNION [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=192&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Verdana;font-size:normal;"><br />
Usually we save Time with Dates in DATETIME column.<br />
Today, I came across situation, where I need to sort my result set by Time, regardless the Date.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:normal;"><br />
Let&#8217;s see Example</span></p>
<p><span style="font-family:Verdana;font-size:normal;">I have some sample data like this:</span></p>
<p><span style="font-family:Courier New;font-size:x-small;"><span style="color:blue;">DECLARE</span> <span style="color:#8000ff;">@Data</span> <span style="color:blue;">TABLE</span><span style="color:maroon;">(</span><span style="color:maroon;">dt</span> <span style="color:black;">DATETIME</span><span style="color:maroon;">)</span></span></p>
<p><span style="color:blue;">INSERT</span> <span style="color:blue;">INTO</span> <span style="color:#8000ff;">@Data</span><span style="color:maroon;">(</span><span style="color:maroon;">dt</span><span style="color:maroon;">)</span><br />
<span style="color:blue;">SELECT</span> <span style="color:red;">&#8217;2008-12-05 04:00:00.000&#8242;</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:red;">&#8217;2008-12-10 10:00:00.000&#8242;</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:red;">&#8217;2009-03-01 08:00:00.000&#8242;</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:red;">&#8217;2009-03-02 07:15:00.000&#8242;</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:red;">&#8217;2009-03-10 08:50:00.000&#8242;</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:red;">&#8217;2008-12-31 23:00:00.000&#8242;</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:red;">&#8217;2009-05-01 21:10:00.000&#8242;</span></p>
<p><span style="color:blue;">SELECT</span> <span style="color:silver;">*</span><br />
<span style="color:blue;">FROM</span> <span style="color:#8000ff;">@Data</span><br />
<span style="font-family:Verdana;font-size:normal;">Now we need output like this:</span></p>
<div id="attachment_195" class="wp-caption alignnone" style="width: 178px"><img class="size-full wp-image-195" title="Get Result Order BY Time regardless Date on DateTime column" src="http://tejasnshah.files.wordpress.com/2009/03/161.jpg?w=450" alt="Get Result Order BY Time regardless Date on DateTime column"   /><p class="wp-caption-text">Get Result Order BY Time regardless Date on DateTime column</p></div>
<p><span style="font-family:Verdana;font-size:normal;"><br />
I found very quick solution for this. You can create query as follows:</span></p>
<p><code><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">SELECT</span> <span style="color:silver;">*</span><br />
<span style="color:blue;">FROM</span> <span style="color:#8000ff;">@Data</span><br />
<span style="color:blue;">ORDER</span> <span style="color:blue;">BY</span> <span style="color:fuchsia;font-weight:bold;">Convert</span><span style="color:maroon;">(</span><span style="color:black;">VARCHAR</span><span style="color:silver;">,</span> <span style="color:maroon;">dt</span><span style="color:silver;">,</span><span style="color:black;">108</span><span style="color:maroon;">)</span></span></code></p>
<p><span style="font-family:Verdana;font-size:normal;"><br />
Let me know if it helps you in any way.<br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=192&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/03/24/sql-server-select-result-order-by-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>

		<media:content url="http://tejasnshah.files.wordpress.com/2009/03/161.jpg" medium="image">
			<media:title type="html">Get Result Order BY Time regardless Date on DateTime column</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER: Display Minutes in Hour Format like HH:MM</title>
		<link>http://tejasnshah.wordpress.com/2009/03/23/sql-server-display-minutes-in-hour-format-like-hhmm/</link>
		<comments>http://tejasnshah.wordpress.com/2009/03/23/sql-server-display-minutes-in-hour-format-like-hhmm/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 12:23:34 +0000</pubDate>
		<dc:creator>Tejas Shah</dc:creator>
				<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Hours]]></category>
		<category><![CDATA[Minutes]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Tejas Shah]]></category>

		<guid isPermaLink="false">http://tejasnshah.wordpress.com/?p=155</guid>
		<description><![CDATA[Usually, we are saving Hours in Minute Format. So if user has entered Hour: 2 Minutes: 15. We will save 135 Minutes in Database, so we can manipulate it easily. Now we need a report in which we need to display this minutes in HH:MM format as user has entered. This is very simple, lets [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=155&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Verdana;font-size:normal;"><br />
Usually, we are saving Hours in Minute Format. So if user has entered<br />
Hour: 2 Minutes: 15. We will save 135 Minutes in Database, so we can manipulate it easily.</span><br />
<span style="font-family:Verdana;font-size:normal;"><br />
Now we need a report in which we need to display this minutes in HH:MM format as user has entered.</span></p>
<p><span style="font-family:Verdana;font-size:normal;">This is very simple, lets see:</span></p>
<p><span style="font-family:Courier New;font-size:normal;"><span style="color:blue;">DECLARE</span> <span style="color:#8000ff;">@t</span> <span style="color:blue;">TABLE</span><span style="color:maroon;">(</span><span style="color:maroon;">Minutes</span> <span style="color:black;">INT</span><span style="color:maroon;">)</span><br />
<span style="color:blue;">INSERT</span> <span style="color:blue;">INTO</span> <span style="color:#8000ff;">@t</span><br />
<span style="color:blue;">SELECT</span> <span style="color:black;">120</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:black;">135</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:black;">135</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:black;">1440</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:black;">640</span><br />
<span style="color:blue;">UNION</span> <span style="color:blue;">ALL</span><br />
<span style="color:blue;">SELECT</span> <span style="color:black;">720</span></span></p>
<p><span style="color:blue;">SELECT</span> <span style="color:maroon;">Minutes</span> <span style="color:silver;">/</span> <span style="color:black;">60</span> <span style="color:blue;">as</span> <span style="color:maroon;">Hours</span><span style="color:silver;">,</span><br />
<span style="color:maroon;">Minutes</span> <span style="color:silver;">%</span> <span style="color:black;">60</span> <span style="color:blue;">AS</span> <span style="color:maroon;">Minutes</span><br />
<span style="color:blue;">FROM</span> <span style="color:#8000ff;">@t</span></p>
<p><span style="font-family:Verdana;font-size:normal;">Let me know if it helps you in any way.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tejasnshah.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tejasnshah.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tejasnshah.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tejasnshah.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tejasnshah.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tejasnshah.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tejasnshah.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tejasnshah.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tejasnshah.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tejasnshah.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tejasnshah.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tejasnshah.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tejasnshah.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tejasnshah.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tejasnshah.wordpress.com&amp;blog=5927057&amp;post=155&amp;subd=tejasnshah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tejasnshah.wordpress.com/2009/03/23/sql-server-display-minutes-in-hour-format-like-hhmm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a3e4b6aae045ee32828eca46032ca6fe?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tejas Shah</media:title>
		</media:content>
	</item>
	</channel>
</rss>
