<?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>Dayananthan's Weblog</title>
	<atom:link href="http://dayananthan.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dayananthan.wordpress.com</link>
	<description>Make New Ideas That Make Your Work Interesting</description>
	<lastBuildDate>Tue, 17 Jan 2012 18:24:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dayananthan.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Dayananthan's Weblog</title>
		<link>http://dayananthan.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dayananthan.wordpress.com/osd.xml" title="Dayananthan&#039;s Weblog" />
	<atom:link rel='hub' href='http://dayananthan.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Query to find index creation date</title>
		<link>http://dayananthan.wordpress.com/2010/09/17/query-to-find-index-creation-date/</link>
		<comments>http://dayananthan.wordpress.com/2010/09/17/query-to-find-index-creation-date/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 14:59:41 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/?p=27</guid>
		<description><![CDATA[The following query will fetch the index creation date. SELECT  name AS IndexName, STATS_DATE(OBJECT_ID,index_id) AS Creation_Date, OBJECT_NAME(OBJECT_ID) AS &#8216;TableName&#8217;  FROM sys.indexes WHERE name like &#8216;%index_name%&#8217; <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=27&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"><span style="color:#000000;">The following query will fetch the index creation date.</span></span></span></p>
<div><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;">SELECT </span></span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"> name</span></span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"> </span></span></span></span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;">AS</span></span><span style="font-size:x-small;"> IndexName</span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">,</span></span><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span></span></span><span style="color:#ff00ff;font-size:x-small;"><span style="color:#ff00ff;font-size:x-small;">STATS_DATE</span></span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">(</span></span><span style="color:#ff00ff;font-size:x-small;"><span style="color:#ff00ff;font-size:x-small;">OBJECT_ID</span></span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">,</span></span><span style="font-size:x-small;">index_id</span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">)</span></span><span style="font-size:x-small;"> </span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;">AS</span></span><span style="font-size:x-small;"> Creation_Date</span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">,</span></span><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span><span style="color:#ff00ff;font-size:x-small;"><span style="color:#ff00ff;font-size:x-small;">OBJECT_NAME</span></span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">(</span></span><span style="color:#ff00ff;font-size:x-small;"><span style="color:#ff00ff;font-size:x-small;">OBJECT_ID</span></span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">)</span></span><span style="font-size:x-small;"> </span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;">AS</span></span><span style="font-size:x-small;"> </span><span style="color:#ff0000;font-size:x-small;"><span style="color:#ff0000;font-size:x-small;">&#8216;TableName&#8217; </span></span></div>
<div><span style="color:#ff0000;font-size:x-small;"> </span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;">FROM </span></span><span style="color:#008000;font-size:x-small;"><span style="color:#008000;font-size:x-small;">sys</span></span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">.</span></span><span style="color:#008000;font-size:x-small;"><span style="color:#008000;font-size:x-small;">indexes</span></span><span style="font-size:x-small;"> </span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;">WHERE </span></span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"><span style="font-size:x-small;">name </span><span style="color:#808080;font-size:x-small;"><span style="color:#808080;font-size:x-small;">like</span></span><span style="font-size:x-small;"> </span><span style="color:#ff0000;font-size:x-small;"><span style="color:#ff0000;font-size:x-small;">&#8216;%index_name%&#8217;</span></span></span></span><span style="color:#0000ff;font-size:x-small;"><span style="color:#0000ff;font-size:x-small;"> </span></span></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=27&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2010/09/17/query-to-find-index-creation-date/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>Query to delete duplicate Records in SQL Server 2005</title>
		<link>http://dayananthan.wordpress.com/2008/07/03/query-to-delete-duplicate-records-in-sql-server-2005/</link>
		<comments>http://dayananthan.wordpress.com/2008/07/03/query-to-delete-duplicate-records-in-sql-server-2005/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 11:23:19 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Important SQL Query]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Utlities]]></category>
		<category><![CDATA[delete duplicate records]]></category>
		<category><![CDATA[duplicate]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/?p=18</guid>
		<description><![CDATA[Suppose we have the situation to delete some duplicate records in our table. Suppose consider one table create table #Test ( EmpID int, EmpName varchar(50) ) &#8211;Insert the Records into #Test table insert into #Test values(1,&#8217;Daya&#8216;) insert into #Test values(1,&#8217;Daya&#8216;) insert into #Test values(1,&#8217;Daya&#8216;) Now i have two duplicate records inserted and i want to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=18&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Suppose we have the situation to delete some duplicate records in our table. Suppose consider one table</p>
<p><span style="color:#0000ff;">create table</span> #Test<br />
(<br />
EmpID<span style="color:#0000ff;"> int</span>,<br />
EmpName <span style="color:#0000ff;">varchar</span>(50)<br />
)</p>
<p><span style="color:#339966;">&#8211;Insert the Records into #Test table</span></p>
<p><span style="color:#0000ff;">insert into</span> #Test values(1,&#8217;<span style="color:#ff0000;">Daya</span>&#8216;)<br />
<span style="color:#0000ff;">insert into</span> #Test values(1,&#8217;<span style="color:#ff0000;">Daya</span>&#8216;)<br />
<span style="color:#0000ff;">insert into</span> #Test values(1,&#8217;<span style="color:#ff0000;">Daya</span>&#8216;)</p>
<p>Now i have two duplicate records inserted and i want to delete those records. The following query will delete the duplicate records</p>
<p><span style="color:#339966;">&#8211;Query to Delete Duplicate Records</span></p>
<p><span style="color:#0000ff;">WITH</span> Emp <span style="color:#0000ff;">AS</span> (<span style="color:#0000ff;">SELECT</span> ROW_NUMBER ( ) <span style="color:#0000ff;">OVER</span> ( <span style="color:#0000ff;">PARTITION BY</span> EmpID, EmpName <span style="color:#0000ff;">ORDER BY</span> EmpID ) <span style="color:#0000ff;">AS</span> RNUM <span style="color:#0000ff;">FROM</span> #Test )<br />
<span style="color:#0000ff;">DELETE FROM</span> Emp <span style="color:#0000ff;">WHERE</span> RNUM &gt; 1</p>
<p> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=18&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/07/03/query-to-delete-duplicate-records-in-sql-server-2005/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>Max value among three columns</title>
		<link>http://dayananthan.wordpress.com/2008/06/12/max-value-among-three-columns/</link>
		<comments>http://dayananthan.wordpress.com/2008/06/12/max-value-among-three-columns/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 08:59:02 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Important SQL Query]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Utlities]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[max value]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/?p=16</guid>
		<description><![CDATA[  The following query will fetch you the max value among three columns Create Table #test (Name Char(10), Qty1 INT, QTY2 INT, QTY3 INT) Insert into #Test (Name, QTY1, QTY2, QTY3) Values (&#8216;Monitor&#8217;,12,13,11) Insert into #Test (Name, QTY1, QTY2, QTY3) Values (&#8216;KeyBoard&#8217;,8,7,6) Insert into #Test (Name, QTY1, QTY2, QTY3) Values (&#8216;Mouse&#8217;,3,2,5) &#8211;Query to get the max among [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=16&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> </p>
<div><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="color:#800000;">The following query will fetch you the max value among three columns</span></span></span></div>
<div><span style="font-size:x-small;color:#0000ff;"></span></div>
<div><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">Create Table #test (Name Char(10), Qty1 INT, QTY2 INT, QTY3 INT)</span></span></div>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">Insert into #Test (Name, QTY1, QTY2, QTY3) Values (&#8216;Monitor&#8217;,12,13,11)</p>
<p>Insert into #Test (Name, QTY1, QTY2, QTY3) Values (&#8216;KeyBoard&#8217;,8,7,6)</p>
<p>Insert into #Test (Name, QTY1, QTY2, QTY3) Values (&#8216;Mouse&#8217;,3,2,5)</p>
<p><span style="color:#800000;"><strong>&#8211;Query to get the max among three columns</strong></span></p>
<p>select [name],(select max(Qty)</p>
<p>                     from   (select QTY1 as Qty</p>
<p>                             union all</p>
<p>                             select QTY2 as Qty</p>
<p>                             union all</p>
<p>                             select QTY3) as Qty) as Maxi</p>
<p>from #test</p>
<p> </p>
<p></span></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=16&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/06/12/max-value-among-three-columns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>Query to Change Column Name in sql server</title>
		<link>http://dayananthan.wordpress.com/2008/05/30/query-to-change-column-name-in-sql-server/</link>
		<comments>http://dayananthan.wordpress.com/2008/05/30/query-to-change-column-name-in-sql-server/#comments</comments>
		<pubDate>Fri, 30 May 2008 06:58:15 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Important SQL Query]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/?p=15</guid>
		<description><![CDATA[I have created an Table Test with wrong column name as EepId instead of EmpID, and now i want to change it to EmpID, the following is the query to get create table Test ( EepID int )  insert into Test values(2)  Now I want EepID column to Change to EmpID. The following is the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=15&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span style="font-size:x-small;color:#0000ff;font-family:Courier New;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">I have created an Table Test with wrong column name as EepId instead of EmpID, and now i want to change it to EmpID, the following is the query to get </span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;color:#0000ff;font-family:Courier New;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">create</span></span><span style="font-size:x-small;font-family:Courier New;"><span style="font-size:10pt;font-family:'Courier New';"> <span style="color:#0000ff;"><span style="color:blue;">table</span></span> Test</span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;color:#808080;font-family:Courier New;"><span style="font-size:10pt;color:gray;font-family:'Courier New';">(</span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;font-family:Courier New;"><span style="font-size:10pt;font-family:'Courier New';">EepID <span style="color:#0000ff;"><span style="color:blue;">int</span></span></span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;color:#808080;font-family:Courier New;"><span style="font-size:10pt;color:gray;font-family:'Courier New';">)</span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;color:#808080;font-family:Courier New;"><span style="font-size:10pt;color:gray;font-family:'Courier New';"> </span></span><span style="font-size:x-small;color:#0000ff;font-family:Courier New;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">insert</span></span><span style="font-size:x-small;font-family:Courier New;"><span style="font-size:10pt;font-family:'Courier New';"> <span style="color:#0000ff;"><span style="color:blue;">into</span></span> Test <span style="color:#0000ff;"><span style="color:blue;">values</span></span><span style="color:#808080;"><span style="color:gray;">(</span></span>2<span style="color:#808080;"><span style="color:gray;">)</span></span></span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;color:#808080;font-family:Courier New;"><span style="font-size:10pt;color:gray;font-family:'Courier New';"> </span></span><strong><span style="font-size:x-small;color:#000080;font-family:Courier New;"><span style="font-weight:bold;font-size:10pt;color:navy;font-family:'Courier New';">Now I want EepID column to Change to EmpID. The following is the solution</span></span></strong></p>
<p class="MsoNormal"><span style="font-size:x-small;color:#808080;font-family:Courier New;"><span style="font-size:10pt;color:gray;font-family:'Courier New';"> </span></span><span style="font-size:x-small;color:#0000ff;font-family:Courier New;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">EXEC</span></span><span style="font-size:x-small;font-family:Courier New;"><span style="font-size:10pt;font-family:'Courier New';"> <span style="color:#800000;"><span style="color:maroon;">sp_rename</span></span> </span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;font-family:Courier New;"><span style="font-size:10pt;font-family:'Courier New';">    @objname <span style="color:#808080;"><span style="color:gray;">=</span></span> <span style="color:#ff0000;"><span style="color:red;">&#8216;Test.EepID&#8217;</span></span><span style="color:#808080;"><span style="color:gray;">,</span></span> </span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;font-family:Courier New;"><span style="font-size:10pt;font-family:'Courier New';">    @newname <span style="color:#808080;"><span style="color:gray;">=</span></span> <span style="color:#ff0000;"><span style="color:red;">&#8216;EmpID&#8217;</span></span><span style="color:#808080;"><span style="color:gray;">,</span></span> </span></span></p>
<p class="MsoNormal"><span style="font-size:x-small;font-family:Courier New;"><span style="font-size:10pt;font-family:'Courier New';">    @objtype <span style="color:#808080;"><span style="color:gray;">=</span></span> <span style="color:#ff0000;"><span style="color:red;">&#8216;COLUMN&#8217;</span></span></span></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=15&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/05/30/query-to-change-column-name-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>Transaction Isolation level</title>
		<link>http://dayananthan.wordpress.com/2008/04/24/transaction-isolation-level/</link>
		<comments>http://dayananthan.wordpress.com/2008/04/24/transaction-isolation-level/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 09:35:48 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/?p=14</guid>
		<description><![CDATA[Few important things about isolation level Read uncommitted When its used, SQL Server not issue shared locks while reading data. So, you can read an uncommitted transaction that might get rolled back later. This isolation level is also called dirty read. This is the lowest isolation level. It ensures only that a physically corrupt data [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=14&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Few important things about isolation level</p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">Read uncommitted</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">When its used, SQL Server not issue shared locks while reading data. So, you can read an uncommitted transaction that might get rolled back later. This isolation level is also called dirty read. This is the lowest isolation level. It ensures only that a physically corrupt data will not be read.</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">Read committed</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">This is the default isolation level in SQL Server. When its used, SQL Server will</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">use shared locks while reading data. It ensures that a physically corrupt data will notbe read and will never read data that another application has changed and not yet committed,but it does not ensure that the data will not be changed before the end of the transaction.</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">Repeatable read</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">When its used, the dirty reads and nonrepeatable reads cannot occur. </span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">It means that locks will be placed on all data that is used in a query, </span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">and another transactions cannot update the data.</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">Nonrepeatable read</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">When a transaction reads the same row more than one time, and between the</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">two (or more) reads, a separate transaction modifies that row. Because the</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">row was modified between reads within the same transaction, each read</span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:10pt;color:navy;font-family:&quot;">produces different values, which introduces inconsistency.</span></strong></p>
<p> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=14&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/04/24/transaction-isolation-level/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>Single column into comma seperated value</title>
		<link>http://dayananthan.wordpress.com/2008/04/24/single-column-into-comma-seperated-value/</link>
		<comments>http://dayananthan.wordpress.com/2008/04/24/single-column-into-comma-seperated-value/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 09:34:45 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Important SQL Query]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Utlities]]></category>
		<category><![CDATA[delimiters]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server 2005]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/?p=13</guid>
		<description><![CDATA[&#8211;Created one Example table create table Events ( PeopleName varchar(50), EventType varchar(50), Events varchar(100) )   &#8211;Model Values insert into Events values(&#8216;Daya&#8217;,&#8216;B&#8217;,&#8216;Drinking&#8217;) insert into Events values(&#8216;Daya&#8217;,&#8216;B&#8217;,&#8216;Washing&#8217;)     &#8211;Created function to take Events with Comma Seperated on EventType basis CREATE FUNCTION dbo.MakeCommaValue (@pC2 AS VARCHAR(10)) RETURNS VARCHAR(8000) AS BEGIN         DECLARE @oResult VARCHAR(8000)          SELECT [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=13&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">&#8211;Created one Example table</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">create</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">table</span> Events</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:gray;font-family:&quot;">(</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">PeopleName <span style="color:blue;">varchar</span><span style="color:gray;">(</span>50<span style="color:gray;">),</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">EventType <span style="color:blue;">varchar</span><span style="color:gray;">(</span>50<span style="color:gray;">),</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">Events <span style="color:blue;">varchar</span><span style="color:gray;">(</span>100<span style="color:gray;">)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:gray;font-family:&quot;">)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:gray;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">&#8211;Model Values</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">insert</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">into</span> Events <span style="color:blue;">values</span><span style="color:gray;">(</span><span style="color:red;">&#8216;Daya&#8217;</span><span style="color:gray;">,</span><span style="color:red;">&#8216;B&#8217;</span><span style="color:gray;">,</span><span style="color:red;">&#8216;Drinking&#8217;</span><span style="color:gray;">)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">insert</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">into</span> Events <span style="color:blue;">values</span><span style="color:gray;">(</span><span style="color:red;">&#8216;Daya&#8217;</span><span style="color:gray;">,</span><span style="color:red;">&#8216;B&#8217;</span><span style="color:gray;">,</span><span style="color:red;">&#8216;Washing&#8217;</span><span style="color:gray;">)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:gray;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:gray;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">&#8211;Created function to take Events with Comma Seperated on EventType basis</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">CREATE</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">FUNCTION</span> dbo<span style="color:gray;">.</span>MakeCommaValue <span style="color:gray;">(</span>@pC2 <span style="color:blue;">AS</span> <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>10<span style="color:gray;">))</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">RETURNS</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>8000<span style="color:gray;">)</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">AS</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">BEGIN</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">DECLARE</span> @oResult <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>8000<span style="color:gray;">)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>         </span><span style="color:blue;">SELECT</span> @oResult<span style="color:gray;">=</span> <span style="color:fuchsia;">COALESCE</span><span style="color:gray;">(</span>@oResult<span style="color:gray;">+</span><span style="color:red;">&#8216;,&#8217;</span><span style="color:gray;">,</span><span style="color:red;">&#8221;</span><span style="color:gray;">)+</span><span style="color:fuchsia;">CAST</span><span style="color:gray;">(</span>Events <span style="color:blue;">AS</span> <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>10<span style="color:gray;">))</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:blue;">FROM</span> Events <span style="color:blue;">WITH</span> <span style="color:gray;">(</span>NOLOCK<span style="color:gray;">)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">WHERE</span> EventType <span style="color:gray;">=</span> @pC2</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">ORDER</span> <span style="color:blue;">BY</span> Events</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>         </span><span style="color:blue;">RETURN</span> @oResult</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">END</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">&#8211;Call the Function like this</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">SELECT</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">DISTINCT</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>PeopleName<span style="color:gray;">,</span>EventType<span style="color:gray;">,</span>dbo<span style="color:gray;">.</span>MakeCommaValue<span style="color:gray;">(</span><span style="color:red;">&#8216;B&#8217;</span><span style="color:gray;">)</span> <span style="color:blue;">as</span> <span style="color:red;">&#8216;Events&#8217;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:blue;">FROM</span> Events</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">&#8211;Result</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">PeopleName<span>   </span>EventType<span>        </span>Events</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">Daya<span>        </span><span>  </span>B<span>                     </span>Drinking<span style="color:gray;">,</span>Washing</span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=13&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/04/24/single-column-into-comma-seperated-value/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>How to find out recently run queries in SQL Server 2005?</title>
		<link>http://dayananthan.wordpress.com/2008/04/24/how-to-find-out-recently-run-queries-in-sql-server-2005/</link>
		<comments>http://dayananthan.wordpress.com/2008/04/24/how-to-find-out-recently-run-queries-in-sql-server-2005/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 09:33:04 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Important SQL Query]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Utlities]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server 2005]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/?p=12</guid>
		<description><![CDATA[Select dmStats.last_execution_time as &#8216;Last Executed Time&#8217;, dmText.text as &#8216;Executed Query&#8217; from sys.dm_exec_query_stats as dmStats Cross apply sys.dm_exec_sql_text(dmStats.sql_handle) as dmText Order By dmStats.last_execution_time desc<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=12&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">Select</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">dmStats<span style="color:gray;">.</span>last_execution_time <span style="color:blue;">as</span> <span style="color:red;">&#8216;Last Executed Time&#8217;</span><span style="color:gray;">,</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">dmText<span style="color:gray;">.</span>text <span style="color:blue;">as</span> <span style="color:red;">&#8216;Executed Query&#8217;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">from</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">sys.dm_exec_query_stats</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">as</span> dmStats</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:gray;font-family:&quot;">Cross</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:gray;">apply</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">sys.dm_exec_sql_text<span style="color:gray;">(</span>dmStats<span style="color:gray;">.</span>sql_handle<span style="color:gray;">)</span> <span style="color:blue;">as</span> dmText</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">Order</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">By</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">dmStats<span style="color:gray;">.</span>last_execution_time <span style="color:blue;">desc</span></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=12&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/04/24/how-to-find-out-recently-run-queries-in-sql-server-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>Query to find orphan tables</title>
		<link>http://dayananthan.wordpress.com/2008/03/13/query-to-find-orphan-tables/</link>
		<comments>http://dayananthan.wordpress.com/2008/03/13/query-to-find-orphan-tables/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 12:44:58 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Important SQL Query]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Utlities]]></category>
		<category><![CDATA[foreign keys]]></category>
		<category><![CDATA[Orphan tables]]></category>
		<category><![CDATA[Relationships]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Query]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/2008/03/13/query-to-find-orphan-tables/</guid>
		<description><![CDATA[The following query will fetch the tables that doesn&#8217;t have relationships. Select ST.[Name] as &#8220;Orphan Tables&#8221; from Sys.Foreign_Keys as SFK Right Join Sys.Tables as ST On ST.object_id = SFK.parent_object_id Or ST.object_id = SFK.referenced_object_id Where SFK.type is null<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=11&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following query will fetch the tables that doesn&#8217;t have relationships.</p>
<p><font size="2" color="#0000ff">Select<font size="2"> ST</font><font size="2" color="#808080">.</font><font size="2">[Name] </font><font size="2" color="#0000ff">as</font><font size="2"> &#8220;Orphan Tables&#8221;</font></p>
<p></font><font size="2" color="#0000ff">from<font size="2"> </font><font size="2" color="#008000">Sys.Foreign_Keys</font><font size="2"> </font><font size="2" color="#0000ff">as</font><font size="2"> SFK </font><font size="2" color="#808080">Right</font><font size="2"> </font><font size="2" color="#808080">Join</font><font size="2"> </font><font size="2" color="#008000">Sys.Tables</font><font size="2"> </font><font size="2" color="#0000ff">as</font><font size="2"> ST</font></p>
<p></font><font size="2" color="#0000ff">On<font size="2"> ST</font><font size="2" color="#808080">.</font><font size="2" color="#ff00ff">object_id</font><font size="2"> </font><font size="2" color="#808080">=</font><font size="2"> SFK</font><font size="2" color="#808080">.</font><font size="2">parent_object_id </font><font size="2" color="#808080">Or</font></p>
<p></font><font size="2">ST<font size="2" color="#808080">.</font><font size="2" color="#ff00ff">object_id</font><font size="2"> </font><font size="2" color="#808080">=</font><font size="2"> SFK</font><font size="2" color="#808080">.</font><font size="2">referenced_object_id</font></p>
<p></font><font size="2" color="#0000ff">Where<font size="2"> SFK</font><font size="2" color="#808080">.</font><font size="2" color="#0000ff">type</font><font size="2"> </font><font size="2" color="#808080">is</font><font size="2"> </font><font size="2" color="#808080">null</font></p>
<p></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=11&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/03/13/query-to-find-orphan-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>Problem With Nulls in XML generation</title>
		<link>http://dayananthan.wordpress.com/2008/01/29/probelm-with-nulls-in-xml-generation/</link>
		<comments>http://dayananthan.wordpress.com/2008/01/29/probelm-with-nulls-in-xml-generation/#comments</comments>
		<pubDate>Tue, 29 Jan 2008 12:18:19 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Important SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Utlities]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[for xml]]></category>
		<category><![CDATA[NULL in XML]]></category>
		<category><![CDATA[NULL values in XML]]></category>
		<category><![CDATA[xml generation]]></category>
		<category><![CDATA[XML workshop]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/?p=10</guid>
		<description><![CDATA[Suppose we have to display all the data in the table into an XML format and at that time we have some null values in the table. Sometime few peoples will face an issue that they want &#8220;NULL&#8221; to displayed in XML for the null data. So we can we use query like this to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=10&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Suppose we have to display all the data in the table into an XML format and at that time we have some null values in the table. Sometime few peoples will face an issue that they want &#8220;NULL&#8221; to displayed in XML for the null data. So we can we use query like this to get it.</p>
<p><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;">Code:</span></font><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;"> </span></font></p>
<p><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;"></span></font><font size="2" color="#0000ff" face="Courier New"><span style="font-size:10pt;color:blue;font-family:'Courier New';">SELECT</span></font><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"> </span></font></p>
<p><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"></span></font><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';">EmpID</span></font><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"> <font color="#0000ff"><span style="color:blue;">AS</span></font></span></font><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"> <font color="#ff0000"><span style="color:red;">&#8216;empid&#8217;</span></font><font color="#808080"><span style="color:gray;">,</span></font></span></font></p>
<p><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"><font color="#808080"><span style="color:gray;"></span></font></span></font><font size="2" color="#ff00ff" face="Courier New"><span style="font-size:10pt;color:fuchsia;font-family:'Courier New';">ISNULL</span></font><font size="2" color="#808080" face="Courier New"><span style="font-size:10pt;color:gray;font-family:'Courier New';">(</span></font><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';">EmpName<font color="#808080"><span style="color:gray;">,</span></font> <font color="#ff0000"><span style="color:red;">&#8216;NULL&#8217;</span></font><font color="#808080"><span style="color:gray;">)</span></font> <font color="#0000ff"><span style="color:blue;">AS</span></font> <font color="#ff0000"><span style="color:red;">&#8216;empname&#8217;</span></font></span></font></p>
<p><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"><font color="#ff0000"><span style="color:red;"></span></font></span></font><font size="2" color="#0000ff" face="Courier New"><span style="font-size:10pt;color:blue;font-family:'Courier New';">FROM</span></font><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"> </span></font><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';">Emp </span></font></p>
<p><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"></span></font><font size="2" color="#0000ff" face="Courier New"><span style="font-size:10pt;color:blue;font-family:'Courier New';">FOR</span></font><font size="2" face="Courier New"><span style="font-size:10pt;font-family:'Courier New';"> <font color="#0000ff"><span style="color:blue;">XML</span></font> <font color="#0000ff"><span style="color:blue;">PATH</span></font><font color="#808080"><span style="color:gray;">(</span></font><font color="#ff0000"><span style="color:red;">&#8216;EmpDetails&#8217;</span></font><font color="#808080"><span style="color:gray;">),</span></font> <font color="#0000ff"><span style="color:blue;">ROOT</span></font><font color="#808080"><span style="color:gray;">(</span></font><font color="#ff0000"><span style="color:red;">&#8216;Employees&#8217;</span></font><font color="#808080"><span style="color:gray;">);</span></font></span></font><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;"></span></font><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;"> </span></font></p>
<p><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;"></span></font><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;">Output:</span></font><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;"> </span></font></p>
<p><span style="font-size:10pt;font-family:Arial;"><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">&lt;Employees&gt;</font></span><span style="font-size:10pt;font-family:Arial;"><font size="2" color="#0000ff">  &lt;EmpDetails&gt;</font></span><span style="font-size:10pt;font-family:Arial;"><font size="2" color="#0000ff">    &lt;empid&gt;1&lt;/empid&gt;</font></span><span style="font-size:10pt;font-family:Arial;"><font size="2" color="#0000ff">    &lt;empname&gt;Dayaa&lt;/empname&gt;</font></span><span style="font-size:10pt;font-family:Arial;"><font size="2" color="#0000ff">  &lt;/EmpDetails&gt;</p>
<p>  &lt;EmpDetails&gt;</p>
<p>    &lt;empid&gt;3&lt;/empid&gt;</p>
<p>    &lt;empname&gt;NULL&lt;/empname&gt;</p>
<p>  &lt;/EmpDetails&gt;</p>
<p>&lt;/Employees&gt;</p>
<p></font></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=10&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/01/29/probelm-with-nulls-in-xml-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server Interview Questions</title>
		<link>http://dayananthan.wordpress.com/2008/01/20/sql-server-interview-questions/</link>
		<comments>http://dayananthan.wordpress.com/2008/01/20/sql-server-interview-questions/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 06:16:56 +0000</pubDate>
		<dc:creator>Dayananthan</dc:creator>
				<category><![CDATA[Important SQL Query]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Utlities]]></category>
		<category><![CDATA[Interview]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Interview questions]]></category>

		<guid isPermaLink="false">http://dayananthan.wordpress.com/2008/01/20/sql-server-interview-questions/</guid>
		<description><![CDATA[Few Interesting Questions and concepts  There are 3 tables Titles, Authors and Title-Authors (check PUBS db). Write the query to get the author name and the number of books written by that author, the result should start from the author who has written the maximum number of books and end with the author who has [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=9&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color:#ff0000;">Few Interesting Questions and concepts</span></strong></p>
<p><strong> There are 3 tables Titles, Authors and Title-Authors (check PUBS db). Write the query to get the author name and the number of books written by that author, the result should start from the author who has written the maximum number of books and end with the author who has written the minimum number of books.</strong></p>
<p><span style="font-size:x-small;color:#0000ff;">SELECT<span style="font-size:x-small;"> authors</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">au_lname</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff00ff;">COUNT</span><span style="font-size:x-small;color:#808080;">(*)</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;">AS</span><span style="font-size:x-small;"> BooksCount </span></span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">FROM<span style="font-size:x-small;"> authors </span><span style="font-size:x-small;color:#808080;">INNER</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#808080;">JOIN</span></span></span><span style="font-size:x-small;color:#0000ff;"> </span><span style="font-size:x-small;">titleauthor <span style="font-size:x-small;color:#0000ff;">ON</span><span style="font-size:x-small;"> authors</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">au_id </span><span style="font-size:x-small;color:#808080;">=</span><span style="font-size:x-small;"> titleauthor</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">au_id </span><span style="font-size:x-small;color:#808080;">INNER</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#808080;">JOIN </span></span><span style="font-size:x-small;"><span style="font-size:x-small;">titles <span style="font-size:x-small;color:#0000ff;">ON</span><span style="font-size:x-small;"> titles</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">title_id </span><span style="font-size:x-small;color:#808080;">=</span><span style="font-size:x-small;"> titleauthor</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">title_id </span></span></span><span style="font-size:x-small;color:#0000ff;">GROUP<span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;">BY</span><span style="font-size:x-small;"> authors</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">au_lname </span></span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ORDER<span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;">BY</span><span style="font-size:x-small;"> BooksCount </span><span style="font-size:x-small;color:#0000ff;">DESC</span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="color:#000000;"><strong>Write a SQL Query to find first day of month?</strong></span></span></span><span style="font-size:x-small;color:#0000ff;"> </span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">SELECT<span style="font-size:x-small;color:#000000;"> </span><span style="font-size:x-small;color:#ff00ff;">DATENAME</span><span style="font-size:x-small;color:#808080;">(</span><span style="font-size:x-small;color:#000000;">dw</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;color:#000000;"> </span><span style="font-size:x-small;color:#ff00ff;">DATEADD</span><span style="font-size:x-small;color:#808080;">(</span><span style="font-size:x-small;color:#000000;">dd</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;color:#000000;"> </span><span style="font-size:x-small;color:#808080;">-</span><span style="font-size:x-small;color:#000000;"> </span><span style="font-size:x-small;color:#ff00ff;">DATEPART</span><span style="font-size:x-small;color:#808080;">(</span><span style="font-size:x-small;color:#000000;">dd</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;color:#000000;"> </span><span style="font-size:x-small;color:#ff00ff;">GETDATE</span><span style="font-size:x-small;color:#808080;">())</span><span style="font-size:x-small;color:#000000;"> </span><span style="font-size:x-small;color:#808080;">+</span><span style="font-size:x-small;color:#000000;"> 1</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;color:#000000;"> </span><span style="font-size:x-small;color:#ff00ff;">GETDATE</span><span style="font-size:x-small;color:#808080;">())) </span></span><span style="font-size:x-small;color:#0000ff;">AS<span style="font-size:x-small;"><span style="color:#000000;"> FirstDay </span></span></span></span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="color:#000000;"><strong> </strong></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="color:#000000;"><strong>There is a table day_temp which has three columns dayid, day and temperature. How do I write a query to get the difference of temperature among each other for seven days of a week?</strong></span></span></span></span><span style="font-size:x-small;color:#0000ff;"> </span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="color:#000000;"><span style="font-size:x-small;color:#0000ff;">SELECT<span style="font-size:x-small;"> a</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">dayid</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;"> a</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">dday</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;"> a</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">tempe</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;"> a</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">tempe </span><span style="font-size:x-small;color:#808080;">-</span><span style="font-size:x-small;"> b</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">tempe </span><span style="font-size:x-small;color:#0000ff;">AS</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff00ff;">Difference</span></span></span></span><span style="font-size:x-small;"><span style="color:#000000;"><span style="font-size:x-small;color:#0000ff;"> </span><span style="font-size:x-small;color:#0000ff;">FROM<span style="font-size:x-small;"> day_temp a </span><span style="font-size:x-small;color:#808080;">INNER</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#808080;">JOIN </span></span><span style="font-size:x-small;">day_temp b <span style="font-size:x-small;color:#0000ff;">ON</span><span style="font-size:x-small;"> a</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">dayid </span><span style="font-size:x-small;color:#808080;">=</span><span style="font-size:x-small;"> b</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">dayid </span><span style="font-size:x-small;color:#808080;">+</span><span style="font-size:x-small;"> 1</span></span></span><span style="font-size:x-small;"> </span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#000000;"><strong>or this query</strong></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;">Select<span style="font-size:x-small;"> a</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;color:#ff00ff;">day</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;"> a</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">degree</span><span style="font-size:x-small;color:#808080;">-</span><span style="font-size:x-small;">b</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">degree </span><span style="font-size:x-small;color:#0000ff;">from</span><span style="font-size:x-small;"> temperature a</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;"> temperature b </span><span style="font-size:x-small;color:#0000ff;">where</span><span style="font-size:x-small;"> a</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">id</span><span style="font-size:x-small;color:#808080;">=</span><span style="font-size:x-small;">b</span><span style="font-size:x-small;color:#808080;">.</span><span style="font-size:x-small;">id</span><span style="font-size:x-small;color:#808080;">+1</span></span></span></span></span><span style="font-size:x-small;color:#0000ff;"> </span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#000000;"><strong>There is a table which contains the names like this. a1, a2, a3, a3, a4, a1, a1, a2 and their salaries. Write a query to get grand total salary, and total salaries of individual employees in one query.</strong></span></span></span><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"> </span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;">SELECT<span style="font-size:x-small;"> empid</span><span style="font-size:x-small;color:#808080;">,</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff00ff;">SUM</span><span style="font-size:x-small;color:#808080;">(</span><span style="font-size:x-small;">salary</span><span style="font-size:x-small;color:#808080;">)</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;">AS</span><span style="font-size:x-small;"> salary</span></span></span><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">FROM<span style="font-size:x-small;"> employee</span></span><span style="font-size:x-small;color:#0000ff;">GROUP<span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;">BY</span><span style="font-size:x-small;"> empid </span><span style="font-size:x-small;color:#0000ff;">WITH</span><span style="font-size:x-small;"> ROLLUP</span></span><span style="font-size:x-small;color:#0000ff;"> </span><span style="font-size:x-small;color:#0000ff;">ORDER<span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;">BY</span><span style="font-size:x-small;"> empid</span></span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>Update With Case</strong></span></span></p>
<table class="MsoNormalTable" style="width:154.05pt;border-collapse:collapse;margin:auto auto auto 4.65pt;" border="0" cellspacing="0" cellpadding="0" width="205">
<tbody>
<tr style="height:12.75pt;">
<td style="width:48pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="64" valign="bottom"><span style="font-size:10pt;font-family:Arial;">EmpID</span></td>
<td style="width:58.05pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="77" valign="bottom"><span style="font-size:10pt;font-family:Arial;">EmpName</span></td>
<td style="width:48pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="64" valign="bottom"><span style="font-size:10pt;font-family:Arial;">Gender</span></td>
</tr>
<tr style="height:12.75pt;">
<td style="width:48pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="64" valign="bottom"><span style="font-size:10pt;font-family:Arial;">1</span></td>
<td style="width:58.05pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="77" valign="bottom"><span style="font-size:10pt;font-family:Arial;">Raja</span></td>
<td style="width:48pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="64" valign="bottom"><span style="font-size:10pt;font-family:Arial;">Male</span></td>
</tr>
<tr style="height:12.75pt;">
<td style="width:48pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="64" valign="bottom"><span style="font-size:10pt;font-family:Arial;">2</span></td>
<td style="width:58.05pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="77" valign="bottom"><span style="font-size:10pt;font-family:Arial;">Rani</span></td>
<td style="width:48pt;height:12.75pt;background-color:transparent;border:#ece9d8;padding:0 5.4pt;" width="64" valign="bottom"><span style="font-size:10pt;font-family:Arial;">Female</span></td>
</tr>
</tbody>
</table>
<p><span style="font-size:x-small;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>In the above table using one query u need to change Gender male to female and who is female need to change male.</strong></span></span></span><span style="font-size:x-small;"><span style="font-size:small;font-family:Times New Roman;"><strong> </strong></span></span></p>
<p><span style="font-size:x-small;"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">UPDATE</span><span style="font-size:10pt;font-family:'Courier New';"> Emp1 <span style="color:#0000ff;">SET</span> Gender<span style="color:#808080;">=</span></span><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">CASE</span><span style="font-size:10pt;font-family:'Courier New';"> Gender <span style="color:#0000ff;">WHEN</span> <span style="color:#ff0000;">&#8216;Male&#8217;</span> <span style="color:#0000ff;">THEN</span> <span style="color:#ff0000;">&#8216;Female&#8217;</span></span><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">WHEN</span><span style="font-size:10pt;font-family:'Courier New';"> <span style="color:#ff0000;">&#8216;female&#8217;</span> <span style="color:#0000ff;">THEN</span> <span style="color:#ff0000;">&#8216;Male&#8217;</span></span><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">END</span><span style="font-size:10pt;color:#808080;font-family:'Courier New';">;</span></span><strong></strong></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><strong><span style="font-size:small;"><span style="color:#000000;"><span style="font-family:Times New Roman;">Query to find the maximum salary of an employee </span></span></span></strong><strong><span style="font-size:10pt;color:#000000;font-family:'Courier New';"> </span></strong></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><strong></strong><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">Select</span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"> </span><span style="color:#808080;">*</span><span style="color:#000000;"> </span><span style="color:#0000ff;">from</span><span style="color:#000000;"> Employee </span><span style="color:#0000ff;">where</span><span style="color:#000000;"> salary </span><span style="color:#808080;">=</span><span style="color:#000000;"> </span><span style="color:#808080;">(</span><span style="color:#0000ff;">Select</span><span style="color:#000000;"> </span><span style="color:#ff00ff;">max</span><span style="color:#808080;">(</span><span style="color:#000000;">Salary</span><span style="color:#808080;">)</span><span style="color:#000000;"> </span><span style="color:#0000ff;">from</span><span style="color:#000000;"> Employee</span><span style="color:#808080;">)</span></span><span style="font-size:10pt;color:#808080;font-family:'Courier New';"> </span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><strong><span style="font-size:small;"><span style="color:#000000;"><span style="font-family:Times New Roman;">Query to Find the Nth Maximum Salary</span></span></span></strong><span style="font-size:10pt;color:#808080;font-family:'Courier New';"> </span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">Select</span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"> </span><span style="color:#808080;">*</span><span style="color:#000000;"> </span><span style="color:#0000ff;">From</span><span style="color:#000000;"> Employee E1 </span><span style="color:#0000ff;">Where</span></span><span style="font-size:10pt;font-family:'Courier New';"><span><span style="color:#000000;">    </span></span><span style="color:#808080;">(</span><span style="color:#000000;">3</span><span style="color:#808080;">-</span><span style="color:#000000;">1</span><span style="color:#808080;">)</span><span style="color:#000000;"> </span><span style="color:#808080;">=</span><span style="color:#000000;"> </span><span style="color:#808080;">(</span><span style="color:#0000ff;">Select</span><span style="color:#000000;"> </span><span style="color:#ff00ff;">Count</span><span style="color:#808080;">(</span><span style="color:#0000ff;">Distinct</span><span style="color:#808080;">(</span><span style="color:#000000;">E2</span><span style="color:#808080;">.</span><span style="color:#000000;">Salary</span><span style="color:#808080;">))</span><span style="color:#000000;"> </span><span style="color:#0000ff;">From</span><span style="color:#000000;"> Employee E2 </span><span style="color:#0000ff;">Where</span></span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"><span>            </span>E2</span><span style="color:#808080;">.</span><span style="color:#000000;">Salary </span><span style="color:#808080;">&gt;</span><span style="color:#000000;"> E1</span><span style="color:#808080;">.</span><span style="color:#000000;">Salary</span><span style="color:#808080;">)</span></span><span style="font-size:10pt;color:#808080;font-family:'Courier New';"> </span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><strong><span style="font-size:small;"><span style="color:#000000;"><span style="font-family:Times New Roman;">Query to Find the 2nd Maximum Salary</span></span></span></strong><span style="font-size:10pt;color:#808080;font-family:'Courier New';"> </span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">SELECT</span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"> SALARY </span></span><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">FROM</span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"><span>    </span>EMPLOYEE</span></span><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">WHERE</span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"><span>  </span>SALARY</span><span style="color:#808080;">=(</span><span style="color:#0000ff;">SELECT</span><span style="color:#000000;"> </span><span style="color:#ff00ff;">MAX</span><span style="color:#808080;">(</span><span style="color:#000000;">SALARY</span><span style="color:#808080;">) </span></span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#0000ff;">FROM</span><span style="color:#000000;"><span>    </span>EMPLOYEE</span></span><span style="font-size:10pt;font-family:'Courier New';"><span><span style="color:#000000;"> </span></span><span style="color:#0000ff;">WHERE</span><span style="color:#000000;"><span>  </span>SALARY </span><span style="color:#808080;">&lt;&gt;</span><span style="color:#000000;"> </span><span style="color:#808080;">(</span><span style="color:#0000ff;">SELECT</span><span style="color:#000000;"> </span><span style="color:#ff00ff;">MAX </span><span style="color:#808080;">(</span><span style="color:#000000;">SALARY</span><span style="color:#808080;">)</span></span><span style="font-size:10pt;font-family:'Courier New';"><span><span style="color:#000000;"> </span></span><span style="color:#0000ff;">FROM</span><span style="color:#000000;"><span>  </span>EMPLOYEE</span><span style="color:#808080;">))</span></span><span style="font-size:10pt;color:#808080;font-family:'Courier New';"> </span></span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">select</span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"> </span><span style="color:#ff00ff;">max</span><span style="color:#808080;">(</span><span style="color:#000000;">salary</span><span style="color:#808080;">)</span><span style="color:#000000;"> </span><span style="color:#0000ff;">as</span><span style="color:#000000;"> Salary </span><span style="color:#0000ff;">from</span><span style="color:#000000;"> Emplo </span><span style="color:#0000ff;">where</span><span style="color:#000000;"> salary</span><span style="color:#808080;">!=(</span><span style="color:#0000ff;">select</span><span style="color:#000000;"> </span><span style="color:#ff00ff;">max</span><span style="color:#808080;">(</span><span style="color:#000000;">salary</span><span style="color:#808080;">)</span><span style="color:#000000;"> </span><span style="color:#0000ff;">from</span><span style="color:#000000;"> Emplo</span><span style="color:#808080;">)</span></span><span style="font-size:10pt;color:#808080;font-family:'Courier New';"> </span></span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">SELECT</span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"> </span><span style="color:#ff00ff;">MAX</span><span style="color:#808080;">(</span><span style="color:#000000;">E1</span><span style="color:#808080;">.</span><span style="color:#000000;">salary</span><span style="color:#808080;">)</span><span><span style="color:#000000;">  </span></span><span style="color:#0000ff;">FROM</span><span style="color:#000000;"> emplo E1 </span><span style="color:#808080;">,</span><span style="color:#000000;"> emplo E2</span></span><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">WHERE</span><span style="font-size:10pt;font-family:'Courier New';"><span style="color:#000000;"> E1</span><span style="color:#808080;">.</span><span style="color:#000000;">salary</span><span style="color:#808080;">&lt;</span><span style="color:#000000;"> E2</span><span style="color:#808080;">.</span><span style="color:#000000;">salary</span></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"></span></span></span></span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><strong><span style="font-size:9pt;font-family:Arial;">Creating a foreign-key constraint between columns of two tables defined with two different datatypes will produce an error</span></strong></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#800000;"><strong><span style="font-size:9pt;font-family:Arial;">Ans : Yes</span></strong></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#800000;"><strong></strong></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><strong></strong></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><strong><span style="color:#ff0000;">Important concepts</span></strong></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><strong>What’s the difference between a primary key and a unique key?</strong><br />
 Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn’t allow NULLs, but unique key allows one NULL only.</p>
<p><strong>Define candidate key, alternate key, composite key.</strong><br />
 A candidate key is one that can identify each row of a table uniquely. Generally a candidate key becomes the primary key of the table. If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys. A key formed by combining at least two or more columns is called composite key.<br />
<strong>What is a transaction and what are ACID properties? </strong><br />
 A transaction is a logical unit of work in which, all the steps must be performed or none. ACID stands for Atomicity, Consistency, Isolation, Durability. These are the properties of a transaction. For more information and explanation of these properties, see SQL Server books online or any RDBMS fundamentals text book. Explain different isolation levels An isolation level determines the degree of isolation of data between concurrent transactions. The default SQL Server isolation level is Read Committed. Here are the other isolation levels (in the ascending order of isolation): Read Uncommitted, Read Committed, Repeatable Read, Serializable. See SQL Server books online for an explanation of the isolation levels. Be sure to read about SET TRANSACTION ISOLATION LEVEL, which lets you customize the isolation level at the connection level. Read Committed &#8211; A transaction operating at the Read Committed level cannot see changes made by other transactions until those transactions are committed. At this level of isolation, dirty reads are not possible but nonrepeatable reads and phantoms are possible. Read Uncommitted &#8211; A transaction operating at the Read Uncommitted level can see uncommitted changes made by other transactions. At this level of isolation, dirty reads, nonrepeatable reads, and phantoms are all possible. Repeatable Read &#8211; A transaction operating at the Repeatable Read level is guaranteed not to see any changes made by other transactions in values it has already read. At this level of isolation, dirty reads and nonrepeatable reads are not possible but phantoms are possible. Serializable &#8211; A transaction operating at the Serializable level guarantees that all concurrent transactions interact only in ways that produce the same effect as if each transaction were entirely executed one after the other. At this isolation level, dirty reads, nonrepeatable reads, and phantoms are not possible.<br />
<strong>What’s the difference between DELETE TABLE and TRUNCATE TABLE commands?<br />
</strong> DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it won’t log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back. TRUNCATE TABLE is functionally identical to DELETE statement with no WHERE clause: both remove all rows in the table. But TRUNCATE TABLE is faster and uses fewer system and transaction log resources than DELETE. The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row. TRUNCATE TABLE removes the data by deallocating the data pages used to store the table’s data, and only the page deallocations are recorded in the transaction log. TRUNCATE TABLE removes all rows from a table, but the table structure and its columns, constraints, indexes and so on remain. The counter used by an identity for new rows is reset to the seed for the column. If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement. You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint; instead, use DELETE statement without a WHERE clause. Because TRUNCATE TABLE is not logged, it cannot activate a trigger. TRUNCATE TABLE may not be used on tables participating in an indexed view</p>
<p><strong>What are the steps you will take to improve performance of a poor performing query? </strong><br />
 This is a very open ended question and there could be a lot of reasons behind the poor performance of a query. But some general issues that you could talk about would be: No indexes, table scans, missing or out of date statistics, blocking, excess recompilations of stored procedures, procedures and triggers without SET NOCOUNT ON, poorly written query with unnecessarily complicated joins, too much normalization, excess usage of cursors and temporary tables. Some of the tools/ways that help you troubleshooting performance problems are: SET SHOWPLAN_ALL ON, SET SHOWPLAN_TEXT ON, SET STATISTICS IO ON, SQL Server Profiler, Windows NT /2000 Performance monitor, Graphical execution plan in Query Analyzer</p>
<p><strong> What is a deadlock and what is a live lock? How will you go about resolving deadlocks?</strong><br />
  Deadlock is a situation when two processes, each having a lock on one piece of data, attempt to acquire a lock on the other’s piece. Each process would wait indefinitely for the other to release the lock, unless one of the user processes is terminated. SQL Server detects deadlocks and terminates one user’s process. A livelock is one, where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. SQL Server detects the situation after four denials and refuses further shared locks. A livelock also occurs when read transactions monopolize a table or page, forcing a write transaction to wait indefinitely. Check out SET DEADLOCK_PRIORITY and &#8220;Minimizing Deadlocks&#8221; in SQL Server books online</p>
<p><strong>What are statistics, under what circumstances they go out of date, how do you update them?<br />
</strong>  Statistics determine the selectivity of the indexes. If an indexed column has unique values then the selectivity of that index is more, as opposed to an index with non-unique values. Query optimizer uses these indexes in determining whether to choose an index or not while executing a query. Some situations under which you should update statistics: 1) If there is significant change in the key values in the index 2) If a large amount of data in an indexed column has been added, changed, or removed (that is, if the distribution of key values has changed), or the table has been truncated using the TRUNCATE TABLE statement and then repopulated 3) Database is upgraded from a previous version. Look up SQL Server books online for the following commands: UPDATE STATISTICS, STATS_DATE, DBCC SHOW_STATISTICS, CREATE STATISTICS, DROP STATISTICS, sp_autostats, sp_createstats, sp_updatestats</p>
<p><strong> Index Optimization tips</strong><br />
• Every index increases the time in takes to perform INSERTS, UPDATES and DELETES, so the number of indexes should not be very much. Try to use maximum 4-5 indexes on one table, not more. If you have read-only table, then the number of indexes may be increased.<br />
• Keep your indexes as narrow as possible. This reduces the size of the index and reduces the number of reads required to read the index.<br />
• Try to create indexes on columns that have integer values rather than character values.<br />
• If you create a composite (multi-column) index, the order of the columns in the key are very important. Try to order the columns in the key as to enhance selectivity, with the most selective columns to the leftmost of the key.<br />
• If you want to join several tables, try to create surrogate integer keys for this purpose and create indexes on their columns.<br />
• Create surrogate integer primary key (identity for example) if your table will not have many insert operations.<br />
• Clustered indexes are more preferable than nonclustered, if you need to select by a range of values or you need to sort results set with GROUP BY or ORDER BY.<br />
• If your application will be performing the same query over and over on the same table, consider creating a covering index on the table.<br />
• You can use the SQL Server Profiler Create Trace Wizard with &#8220;Identify Scans of Large Tables&#8221; trace to determine which tables in your database may need indexes. This trace will show which tables are being scanned by queries instead of using an index.<br />
• You can use sp_MSforeachtable undocumented stored procedure to rebuild all indexes in your database. Try to schedule it to execute during CPU idle time and slow production periods.<br />
sp_MSforeachtable @command1=&#8221;print &#8216;?&#8217; DBCC DBREINDEX (&#8216;?&#8217;)&#8221;</p>
<p><strong>Explain about Clustered and non clustered index? How to choose between a Clustered Index and a Non-Clustered Index?<br />
</strong>There are clustered and nonclustered indexes. A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.<br />
A nonclustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf nodes of a nonclustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.<br />
Consider using a clustered index for:<br />
o Columns that contain a large number of distinct values.<br />
o Queries that return a range of values using operators such as BETWEEN, &gt;, &gt;=, &lt;, and &lt;=.<br />
o Columns that are accessed sequentially.<br />
o Queries that return large result sets.<br />
Non-clustered indexes have the same B-tree structure as clustered indexes, with two significant differences:<br />
o The data rows are not sorted and stored in order based on their non-clustered keys.<br />
o The leaf layer of a non-clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows. Each index row contains the non-clustered key value and one or more row locators that point to the data row (or rows if the index is not unique) having the key value.<br />
o Per table only 249 non clustered indexes</p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"></span></span></span></span></span></span></span></span></span></span><strong> How many types of Joins?</strong><br />
Joins can be categorized as:<br />
• Inner joins (the typical join operation, which uses some comparison operator like = or &lt;&gt;). These include equi-joins and natural joins.<br />
Inner joins use a comparison operator to match rows from two tables based on the values in common columns from each table. For example, retrieving all rows where the student identification number is the same in both the students and courses tables.<br />
• Outer joins. Outer joins can be a left, a right, or full outer join.<br />
Outer joins are specified with one of the following sets of keywords when they are specified in the FROM clause:<br />
• LEFT JOIN or LEFT OUTER JOIN -The result set of a left outer join includes all the rows from the left table specified in the LEFT OUTER clause, not just the ones in which the joined columns match. When a row in the left table has no matching rows in the right table, the associated result set row contains null values for all select list columns coming from the right table.<br />
• RIGHT JOIN or RIGHT OUTER JOIN &#8211; A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time a right table row has no matching row in the left table.<br />
• FULL JOIN or FULL OUTER JOIN &#8211; A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables.<br />
• Cross joins &#8211; Cross joins return all rows from the left table, each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products. (A Cartesian join will get you a Cartesian product. A Cartesian join is when you join every row of one table to every row of another table. You can also get one by joining every row of a table to every row of itself.</p>
<p><strong>What are the difference between a function and a stored procedure?</strong><br />
  Functions can be used in a select statement where as procedures cannot <br />
  Procedure takes both input and output parameters but Functions takes only input parameters<br />
  Functions cannot return values of type text, ntext, image &amp; timestamps where as procedures can<br />
  Functions can be used as user defined datatypes in create table but procedures cannot<br />
***Eg:-create table &lt;tablename&gt;(name varchar(10),salary getsal(name))<br />
Here getsal is a user defined function which returns a salary type, when table is created no storage is allotted for salary type, and getsal function is also not executed, But when we are fetching some values from this table, getsal function get’s executed and the return<br />
Type is returned as the result set.</p>
<p><strong>What is the basic functions for master, msdb, tempdb databases?</strong><br />
Microsoft® SQL Server 2000 systems have four system databases:<br />
• master &#8211; The master database records all of the system level information for a SQL Server system. It records all login accounts and all system configuration settings. master is the database that records the existence of all other databases, including the location of the database files.<br />
• tempdb &#8211; tempdb holds all temporary tables and temporary stored procedures. It also fills any other temporary storage needs such as work tables generated by SQL Server. tempdb is re-created every time SQL Server is started so the system starts with a clean copy of the database.<br />
By default, tempdb autogrows as needed while SQL Server is running. If the size defined for tempdb is small, part of your system processing load may be taken up with autogrowing tempdb to the size needed to support your workload each time to restart SQL Server. You can avoid this overhead by using ALTER DATABASE to increase the size of tempdb.<br />
• model &#8211; The model database is used as the template for all databases created on a system. When a CREATE DATABASE statement is issued, the first part of the database is created by copying in the contents of the model database, then the remainder of the new database is filled with empty pages. Because tempdb is created every time SQL Server is started, the model database must always exist on a SQL Server system.<br />
• msdb &#8211; The msdb database is used by SQL Server Agent for scheduling alerts and jobs, and recording operators.</p>
<p><strong>1st Normal Form (1NF)</strong><br />
Definition: A table (relation) is in 1NF if<br />
1. There are no duplicated rows in the table.<br />
2. Each cell is single-valued (i.e., there are no repeating groups or arrays).<br />
3. Entries in a column (attribute, field) are of the same kind.<br />
Note: The order of the rows is immaterial; the order of the columns is immaterial.<br />
Note: The requirement that there be no duplicated rows in the table means that the table has a key (although the key might be made up of more than one column—even, possibly, of all the columns).<br />
Rule 1: Eliminate Repeating Groups. Make a separate table for each set of related attributes, and give each table a primary key.<br />
<strong>2nd Normal Form (2NF)</strong><br />
Definition: A table is in 2NF if it is in 1NF and if all non-key attributes are dependent on all of the key.<br />
Note: Since a partial dependency occurs when a non-key attribute is dependent on only a part of the (composite) key, the definition of 2NF is sometimes phrased as, &#8220;A table is in 2NF if it is in 1NF and if it has no partial dependencies.&#8221;<br />
Rule 2: Eliminate Redundant Data. If an attribute depends on only part of a multi-valued key, remove it to a separate table.<br />
<strong>3rd Normal Form (3NF)</strong><br />
Definition: A table is in 3NF if it is in 2NF and if it has no transitive dependencies.<br />
Rule 3: Eliminate Columns Not Dependent on Key. If attributes do not contribute to a description of the key, remove them to a separate table.<br />
<strong>Boyce-Codd Normal Form (BCNF)<br />
</strong>Definition: A table is in BCNF if it is in 3NF and if every determinant is a candidate key.<br />
<strong>4th Normal Form (4NF)</strong><br />
Definition: A table is in 4NF if it is in BCNF and if it has no multi-valued dependencies.<br />
Rule 4: Isolate Independent Multiple Relationships. No table may contain two or more l:n or n:m relationships that are not directly related.<br />
<strong>5th Normal Form (5NF)</strong><br />
Definition: A table is in 5NF, also called &#8220;Projection-Join Normal Form&#8221; (PJNF), if it is in 4NF and if every join dependency in the table is a consequence of the candidate keys of the table.<br />
Rule 5: Isolate Semantically Related Multiple Relationships. There may be practical constraints on information that justify separating logically related many-to-many relationships.<br />
<strong>Domain-Key Normal Form (DKNF)</strong><br />
Definition: A table is in DKNF if every constraint on the table is a logical consequence of the definition of keys and domains.</p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><strong><span style="color:#ff0000;">Keep on coming&#8230;. Dayaa</span></strong></span></span></span></span></span></span></span></span></span></span></span></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dayananthan.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dayananthan.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dayananthan.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dayananthan.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dayananthan.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dayananthan.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dayananthan.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dayananthan.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dayananthan.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dayananthan.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dayananthan.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dayananthan.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dayananthan.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dayananthan.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dayananthan.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dayananthan.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dayananthan.wordpress.com&amp;blog=2231992&amp;post=9&amp;subd=dayananthan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dayananthan.wordpress.com/2008/01/20/sql-server-interview-questions/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f73c4c1b7cac9ff5f38e2c90d1f4a8ae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dayananthan</media:title>
		</media:content>
	</item>
	</channel>
</rss>
