<?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>Journey to SQL Authority with Pinal Dave &#187; SQL Cursor</title>
	<atom:link href="http://blog.sqlauthority.com/category/sql-cursor/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 01:30:19 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='blog.sqlauthority.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/08e35387c05b61340e885b1763a69d9f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Journey to SQL Authority with Pinal Dave &#187; SQL Cursor</title>
		<link>http://blog.sqlauthority.com</link>
	</image>
			<item>
		<title>SQL SERVER &#8211; 2008 &#8211; 2005 &#8211; Rebuild Every Index of All Tables of Database &#8211; Rebuild Index with FillFactor</title>
		<link>http://blog.sqlauthority.com/2009/01/30/sql-server-2008-2005-rebuild-every-index-of-all-tables-of-database-rebuild-index-with-fillfactor/</link>
		<comments>http://blog.sqlauthority.com/2009/01/30/sql-server-2008-2005-rebuild-every-index-of-all-tables-of-database-rebuild-index-with-fillfactor/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 01:30:12 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2210</guid>
		<description><![CDATA[I just wrote down following script very quickly for one of the project which I am working on. The requirement of the project was that every index existed in database should be rebuilt with fillfactor of  80. One common question I receive why fillfactor 80, answer is I just think having it 80 will do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=2210&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I just wrote down following script very quickly for one of the project which I am working on. The requirement of the project was that every index existed in database should be rebuilt with fillfactor of  80. One common question I receive why fillfactor 80, answer is I just think having it 80 will do the job.Fillfactor determines how much percentage of the space on each leaf-level page are filled with data.</p>
<p style="text-align:justify;">The space which is left empty on leaf-level page is not at end of the page but the empty space is reserved between rows of data. This ensures that rearrangement of the data does not happen every time new data rows are inserted.</p>
<p style="text-align:justify;">Following is <strong>incorrect </strong>image of leaf-level page of fillfactor.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/fillfactor1.jpg" alt="" width="100" height="298" /></p>
<p style="text-align:justify;">Following is <strong>correct </strong>image of leaf-level page of fillfactor.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/fillfactor2.jpg" alt="" width="100" height="300" /></p>
<p style="text-align:justify;">Let us see the T-SQL script which will rebuild each index of all tables of any particular database. Following script will work with SQL Server 2005 (SP2) and SQL Server 2008. It is simple cursor going over each table and rebuilding every index of database.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@TableName </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@sql </span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">500</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@fillfactor </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@fillfactor </span><span style="color:blue;">= </span><span style="color:black;">80<br />
</span><span style="color:blue;">DECLARE </span><span style="color:black;">TableCursor </span><span style="color:blue;">CURSOR FOR<br />
SELECT </span><span style="color:black;">OBJECT_SCHEMA_NAME</span><span style="color:gray;">(</span><span style="color:black;">[object_id]</span><span style="color:gray;">)+</span><span style="color:red;">'.'</span><span style="color:gray;">+</span><span style="color:black;">name </span><span style="color:blue;">AS </span><span style="color:black;">TableName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.tables<br />
</span><span style="color:blue;">OPEN </span><span style="color:black;">TableCursor<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT </span><span style="color:blue;">FROM </span><span style="color:black;">TableCursor </span><span style="color:blue;">INTO </span><span style="color:#434343;">@TableName<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@@FETCH_STATUS </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@sql </span><span style="color:blue;">= </span><span style="color:red;">'ALTER INDEX ALL ON ' </span><span style="color:gray;">+ </span><span style="color:#434343;">@TableName </span><span style="color:gray;">+ </span><span style="color:red;">' REBUILD WITH (FILLFACTOR = ' </span><span style="color:gray;">+ </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">3</span><span style="color:gray;">),</span><span style="color:#434343;">@fillfactor</span><span style="color:gray;">) + </span><span style="color:red;">')'<br />
</span><span style="color:blue;">EXEC </span><span style="color:gray;">(</span><span style="color:#434343;">@sql</span><span style="color:gray;">)<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT </span><span style="color:blue;">FROM </span><span style="color:black;">TableCursor </span><span style="color:blue;">INTO </span><span style="color:#434343;">@TableName<br />
</span><span style="color:blue;">END<br />
CLOSE </span><span style="color:black;">TableCursor<br />
</span><span style="color:blue;">DEALLOCATE </span><span style="color:black;">TableCursor<br />
GO<br />
</span></code>
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Cursor, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLAuthority News, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/2210/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=2210&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/01/30/sql-server-2008-2005-rebuild-every-index-of-all-tables-of-database-rebuild-index-with-fillfactor/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/fillfactor1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/fillfactor2.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Simple Use of Cursor to Print All Stored Procedures of Database</title>
		<link>http://blog.sqlauthority.com/2008/11/20/sql-server-simple-use-of-cursor-to-print-all-stored-procedures-of-database/</link>
		<comments>http://blog.sqlauthority.com/2008/11/20/sql-server-simple-use-of-cursor-to-print-all-stored-procedures-of-database/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 01:30:12 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1544</guid>
		<description><![CDATA[SQLAuthority Blog reader YordanGeorgiev has submitted very interesting SP, which uses cursor to generate text of all the Stored Procedure of current Database. This task can be done many ways, however, this is also interesting method.
USE AdventureWorks
GO
DECLARE @procName VARCHAR(100)
DECLARE @getprocName CURSOR
SET @getprocName = CURSOR FOR
SELECT s.name
FROM sysobjects s
WHERE type = 'P'
OPEN @getprocName
FETCH NEXT
FROM @getprocName INTO @procName
WHILE @@FETCH_STATUS = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1544&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">SQLAuthority Blog reader <a href="http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/#comment-44238" target="_blank">YordanGeorgiev </a>has submitted very interesting SP, which uses cursor to generate text of all the Stored Procedure of current Database. This task can be done many ways, however, this is also interesting method.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@procName </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@getprocName </span><span style="color:blue;">CURSOR<br />
SET </span><span style="color:#434343;">@getprocName </span><span style="color:blue;">= CURSOR FOR<br />
SELECT </span><span style="color:black;">s.name<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sysobjects s<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">type </span><span style="color:blue;">= </span><span style="color:red;">'P'<br />
</span><span style="color:blue;">OPEN </span><span style="color:#434343;">@getprocName<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">@getprocName </span><span style="color:blue;">INTO </span><span style="color:#434343;">@procName<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@@FETCH_STATUS </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN<br />
EXEC </span><span style="color:darkred;">sp_HelpText </span><span style="color:#434343;">@procName<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">@getprocName </span><span style="color:blue;">INTO </span><span style="color:#434343;">@procName<br />
</span><span style="color:blue;">END<br />
CLOSE </span><span style="color:#434343;">@getprocName<br />
</span><span style="color:blue;">DEALLOCATE </span><span style="color:#434343;">@getprocName<br />
</span><span style="color:black;">GO </span></code>
</p>
<p style="text-align:justify;"><span style="color:black;">Just give this script a try and it will print text of all the SP in your database. If you are using Grid View for Result Pan I suggest to change it to Text View (CTRL+T) to read the text easily.</span></p>
<p style="text-align:justify;"><span style="color:black;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong><br />
</span></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Cursor, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1544/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1544/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1544/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1544/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1544/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1544/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1544/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1544/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1544/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1544/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1544&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/11/20/sql-server-simple-use-of-cursor-to-print-all-stored-procedures-of-database/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Guidelines and Coding Standards Complete List Download</title>
		<link>http://blog.sqlauthority.com/2008/09/25/sql-server-guidelines-and-coding-standards/</link>
		<comments>http://blog.sqlauthority.com/2008/09/25/sql-server-guidelines-and-coding-standards/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 01:30:54 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Data Warehousing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Coding Standards]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Data Storage]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[SQLAuthority]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1143</guid>
		<description><![CDATA[SQL SERVER &#8211; Guidelines and Coding Standards complete List Download
Coding standards and guidelines are very important for any developer on the path of successful career. A coding standard is a set of guidelines, rules and regulations on how to write code. Coding standards should be flexible enough or should take care of the situation where [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1143&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=SQL-SERVER-Database-Coding-Standards-and-Guidelines-Complete-List-Download"><strong>SQL SERVER &#8211; Guidelines and Coding Standards complete List Download</strong></a></h2>
<p style="text-align:justify;">Coding standards and guidelines are very important for any developer on the path of successful career. A coding standard is a set of guidelines, rules and regulations on how to write code. Coding standards should be flexible enough or should take care of the situation where they should not prevent best practices for coding. They are basically the guidelines that one should follow for better understanding.</p>
<p style="text-align:justify;">The concept behind implementing coding standards and guidelines, is that the consistency and uniformity in programming so that if multiple people are working on the same code, it becomes easier to communicate, share with or understand each other’s work.</p>
<p style="text-align:justify;">With the goal of promoting good coding standards and guidelines I have created document which can guide developers.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/23/sql-server-coding-standards-guidelines-part-1/" target="_blank"><strong>SQL SERVER &#8211; Guidelines and Coding Standards Part &#8211; 1</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/24/sql-server-coding-standards-guidelines-part-2/" target="_blank"><strong>SQL SERVER &#8211; Guidelines and Coding Standards Part &#8211; 2</strong></a></p>
<h2 style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=SQL-SERVER-Database-Coding-Standards-and-Guidelines-Complete-List-Download"><strong>SQL SERVER &#8211; Guidelines and Coding Standards complete List Download</strong></a></h2>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Best Practices, Data Warehousing, Database, DBA, Pinal Dave, SQL, SQL Authority, SQL Coding Standards, SQL Constraint and Keys, SQL Cursor, SQL Data Storage, SQL Documentation, SQL Download, SQL Function, SQL Index, SQL Joins, SQL Performance, SQL Query, SQL Scripts, SQL Security, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, SQL Trigger, SQL Utility, SQLAuthority, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1143/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1143&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/09/25/sql-server-guidelines-and-coding-standards/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers Complete List Download</title>
		<link>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/</link>
		<comments>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 01:30:39 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Data Storage]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Error Messages]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[SQLAuthority]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL XML]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1134</guid>
		<description><![CDATA[Download SQL Server 2008 Interview Questions and Answers Complete List
Interview is very important event for any person. A good interview leads to good career if candidate is willing to learn. I always enjoy interview questions and answers series. This is my very humble attempt to write SQL Server 2008 interview questions and answers. SQL Server [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1134&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=SQL-SERVER-2008-Download-Interview-Questions-and-Answers"><strong>Download SQL Server 2008 Interview Questions and Answers Complete List</strong></a></h2>
<p style="text-align:justify;">Interview is very important event for any person. A good interview leads to good career if candidate is willing to learn. I always enjoy interview questions and answers series. This is my very humble attempt to write SQL Server 2008 interview questions and answers. SQL Server is very large subject and not everything is usually asked in interview. In interview what matters the most is <strong>conceptual knowledge</strong> and <strong>learning attitude</strong>.</p>
<p style="text-align:justify;">I have listed all the series in this post so that it can be easily downloaded and used. All the questions are collected and listed in one PDF which is here to download. If you have any question or if you want to add to any of the question please send me mail or write a comment.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/12/sql-server-2008-interview-questions-and-answers-part-1/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 1</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/13/sql-server-2008-interview-questions-and-answers-part-2/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 2</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/14/sql-server-2008-interview-questions-and-answers-part-3/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 3</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/15/sql-server-2008-interview-questions-and-answers-part-4/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 4</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/16/sql-server-2008-interview-questions-and-answers-part-5/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 5</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/17/sql-server-2008-interview-questions-and-answers-part-6/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 6</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/18/sql-server-2008-interview-questions-and-answers-part-7/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 7</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/19/sql-server-2008-interview-questions-and-answers-part-8/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 8</strong></a></p>
<h2 style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=SQL-SERVER-2008-Download-Interview-Questions-and-Answers"><strong>Download SQL Server 2008 Interview Questions and Answers Complete List</strong></a></h2>
<p style="text-align:justify;">
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Database, Pinal Dave, SQL, SQL Authority, SQL Constraint and Keys, SQL Cursor, SQL Data Storage, SQL DateTime, SQL Documentation, SQL Download, SQL Error Messages, SQL Function, SQL Index, SQL Interview Questions and Answers, SQL Joins, SQL Performance, SQL Query, SQL Scripts, SQL Security, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, SQL Trigger, SQL Utility, SQLAuthority, T SQL, Technology Tagged: SQL XML <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1134&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 2</title>
		<link>http://blog.sqlauthority.com/2008/09/13/sql-server-2008-interview-questions-and-answers-part-2/</link>
		<comments>http://blog.sqlauthority.com/2008/09/13/sql-server-2008-interview-questions-and-answers-part-2/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 01:30:09 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Data Warehousing]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLAuthority]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=991</guid>
		<description><![CDATA[SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers Complete List Download
1) General Questions of SQL SERVER 
What is Cursor?
Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, instead of the typical SQL commands that operate on all the rows in the set at one time.
In [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=991&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/" target="_blank">SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers Complete List Download</a></strong></h2>
<p style="text-align:justify;"><strong>1) </strong><strong>General Questions of SQL SERVER </strong></p>
<p style="text-align:justify;"><strong>What is Cursor?</strong></p>
<p style="text-align:justify;">Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, instead of the typical SQL commands that operate on all the rows in the set at one time.</p>
<p style="text-align:justify;">In order to work with a cursor we need to perform some steps in the following order:</p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Declare cursor</li>
<li> Open cursor</li>
<li> Fetch row from the cursor</li>
<li> Process fetched row</li>
<li> Close cursor</li>
<li> Deallocate cursor (<a href="http://blog.sqlauthority.com/2008/04/19/sql-server-is-cursor-database-object-or-datatype/" target="_blank">Read More Here</a>)</li>
</ul>
<p style="text-align:justify;"><strong>What is Collation?</strong></p>
<p style="text-align:justify;">Collation refers to a set of rules that determine how data is sorted and compared. Character data is sorted using rules that define the correct character sequence, with options for specifying case sensitivity, accent marks, kana character types and character width. (<a href="http://blog.sqlauthority.com/2007/04/24/sql-server-2005-collation-explanation-and-translation/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>What is Difference between Function and Stored Procedure?</strong></p>
<p style="text-align:justify;">UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be. UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables. Inline UDF&#8217;s can be thought of as views that take parameters and can be used in JOINs and other Rowset operations.</p>
<p style="text-align:justify;"><strong>What is sub-query? Explain properties of sub-query?</strong></p>
<p style="text-align:justify;">Sub-queries are often referred to as sub-selects, as they allow a SELECT statement to be executed arbitrarily within the body of another SQL statement. A sub-query is executed by enclosing it in a set of parentheses. Sub-queries are generally used to return a single row as an atomic value, though they may be used to compare values against multiple rows with the IN keyword.</p>
<p style="text-align:justify;">A subquery is a SELECT statement that is nested within another T-SQL statement. A subquery SELECT statement if executed independently of the T-SQL statement, in which it is nested, will return a resultset. Meaning a subquery SELECT statement can standalone and is not depended on the statement in which it is nested. A subquery SELECT statement can return any number of values, and can be found in, the column list of a SELECT statement, a FROM, GROUP BY, HAVING, and/or ORDER BY clauses of a T-SQL statement. A Subquery can also be used as a parameter to a function call. Basically a subquery can be used anywhere an expression can be used. (<a href="http://blog.sqlauthority.com/2007/09/07/sql-server-correlated-and-noncorrelated-subquery-introduction-explanation-and-example/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>What are different Types of Join?</strong></p>
<p style="text-align:justify;"><strong><em>Cross Join</em></strong></p>
<p style="text-align:justify;">A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table. The common example is when company wants to combine each product with a pricing table to analyze each product at each price.</p>
<p style="text-align:justify;"><strong><em>Inner Join</em></strong></p>
<p style="text-align:justify;">A join that displays only the rows that have a match in both joined tables is known as inner Join.  This is the default type of join in the Query and View Designer.</p>
<p style="text-align:justify;"><strong><em>Outer Join</em></strong></p>
<p style="text-align:justify;">A join that includes rows even if they do not have related rows in the joined table is an Outer Join.  You can create three different outer join to specify the unmatched rows to be included:</p>
<ul class="unIndentedList" style="text-align:justify;">
<li> <strong>Left Outer Join:</strong> In Left Outer Join all rows in the first-named table i.e. &#8220;left&#8221; table, which appears leftmost in the JOIN clause are included. Unmatched rows in the right table do not appear.<strong> </strong><strong><em> </em></strong></li>
</ul>
<p style="text-align:justify;"><strong><em> </em></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> <strong>Right Outer Join:</strong> In Right Outer Join all rows in the second-named table i.e. &#8220;right&#8221; table, which appears rightmost in the JOIN clause are included. Unmatched rows in the left table are not included.<strong><em></em></strong></li>
</ul>
<p style="text-align:justify;"><strong><em> </em></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> <strong>Full Outer Join:</strong> In Full Outer Join all rows in all joined tables are included, whether they are matched or not.<strong></strong></li>
</ul>
<p style="text-align:justify;"><strong><em>Self Join</em></strong></p>
<p style="text-align:justify;">This is a particular case when one table joins to itself, with one or two aliases to avoid confusion. A self join can be of any type, as long as the joined tables are the same. A self join is rather unique in that it involves a relationship with only one table. The common example is when company has a hierarchal reporting structure whereby one member of staff reports to another. Self Join can be Outer Join or Inner Join. (<a href="http://blog.sqlauthority.com/2007/06/03/sql-server-2005-explanation-and-example-self-join/" target="_blank">Read More Here</a>)<strong></strong></p>
<p style="text-align:justify;"><strong>What are primary keys and foreign keys?</strong></p>
<p style="text-align:justify;">Primary keys are the unique identifiers for each row. They must contain unique values and cannot be null. Due to their importance in relational databases, Primary keys are the most fundamental of all keys and constraints. A table can have only one Primary key.</p>
<p style="text-align:justify;">Foreign keys are both a method of ensuring data integrity and a manifestation of the relationship between tables.</p>
<p style="text-align:justify;"><strong>What is User Defined Functions? What kind of User-Defined Functions can be created?</strong></p>
<p style="text-align:justify;">User-Defined Functions allow defining its own T-SQL functions that can accept 0 or more parameters and return a single scalar data value or a table data type.</p>
<p style="text-align:justify;"><em>Different Kinds of User-Defined Functions created are: </em></p>
<p style="text-align:justify;"><strong><em>Scalar User-Defined Function</em></strong></p>
<p style="text-align:justify;">A Scalar user-defined function returns one of the scalar data types. Text, ntext, image and timestamp data types are not supported. These are the type of user-defined functions that most developers are used to in other programming languages. You pass in 0 to many parameters and you get a return value.</p>
<p style="text-align:justify;"><strong><em>Inline Table-Value User-Defined Function</em></strong></p>
<p style="text-align:justify;">An Inline Table-Value user-defined function returns a table data type and is an exceptional alternative to a view as the user-defined function can pass parameters into a T-SQL select command and in essence provide us with a parameterized, non-updateable view of the underlying tables.<strong><em></em></strong></p>
<p style="text-align:justify;"><strong><em>Multi-statement Table-Value User-Defined Function</em></strong></p>
<p style="text-align:justify;">A Multi-Statement Table-Value user-defined function returns a table and is also an exceptional alternative to a view as the function can support multiple T-SQL statements to build the final result where the view is limited to a single SELECT statement. Also, the ability to pass parameters into a TSQL select command or a group of them gives us the capability to in essence create a parameterized, non-updateable view of the data in the underlying tables. Within the create function command you must define the table structure that is being returned. After creating this type of user-defined function, It can be used in the FROM clause of a T-SQL command unlike the behavior found when using a stored procedure which can also return record sets. (<a href="http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/" target="_blank">Read Here For Example</a>)</p>
<p style="text-align:justify;"><strong>What is Identity?</strong></p>
<p style="text-align:justify;">Identity (or AutoNumber) is a column that automatically generates numeric values. A start and increment value can be set, but most DBA leave these at 1. A GUID column also generates numbers; the value of this cannot be controlled. Identity/GUID columns do not need to be indexed.</p>
<p style="text-align:justify;"><strong>What is DataWarehousing?</strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Subject-oriented, meaning that the data in the database is organized so that all the data elements relating to the same real-world event or object are linked together;</li>
<li> Time-variant, meaning that the changes to the data in the database are tracked and recorded so that reports can be produced showing changes over time;</li>
<li> Non-volatile, meaning that data in the database is never over-written or deleted, once committed, the data is static, read-only, but retained for future reporting.</li>
<li> Integrated, meaning that the database contains data from most or all of an organization&#8217;s operational applications, and that this data is made consistent.</li>
</ul>
<p style="text-align:justify;">© Copyright 2000-2009<a title="Pinal Dave" href="http://www.pinaldave.com/" target="_blank"> Pinal Dave.</a> All Rights Reserved. <a href="http://blog.sqlauthority.com/" target="_blank">SQLAuthority.com</a></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/991/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/991/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/991/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/991/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/991/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/991/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/991/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=991&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/09/13/sql-server-2008-interview-questions-and-answers-part-2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Readers Contribution to Site &#8211; Simple Example of Cursor</title>
		<link>http://blog.sqlauthority.com/2008/07/16/sql-server-readers-contribution-to-site-simple-example-of-cursor/</link>
		<comments>http://blog.sqlauthority.com/2008/07/16/sql-server-readers-contribution-to-site-simple-example-of-cursor/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 01:30:05 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=687</guid>
		<description><![CDATA[eaders are very important to me. Without their active participation this site would not be the community helping web site. I encourage readers participation and request that you help other users with your knowledge.
I recently come across very good communication between two of blog readers. I want to thank you Imran Mohammed for taking time [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=687&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">eaders are very important to me. Without their active participation this site would not be the community helping web site. I encourage readers participation and request that you help other users with your knowledge.</p>
<p style="text-align:justify;">I recently come across very good communication between two of blog readers. I want to thank you Imran Mohammed for taking time to answer this question as well many other questions. Expert like Imran makes this world better.</p>
<p style="text-align:justify;">Let us read the question from Anthony from here.</p>
<p style="padding-left:60px;text-align:justify;"><em>All, </em></p>
<p style="padding-left:60px;text-align:justify;"><em>I am using Microsoft SQL 2005 and am trying to create a cursor that will take data from several records and concatenate that data into one record. </em></p>
<p style="padding-left:60px;text-align:justify;"><em>For example: </em></p>
<p style="padding-left:60px;text-align:justify;"><em>I have three attributes (OrderYear, SeqNumber, Item) from a single table (table name: TSGItems) that I am working with… </em></p>
<p style="padding-left:60px;text-align:justify;"><em>The data in TSGItems table looks like this: </em></p>
<p style="padding-left:60px;text-align:justify;"><em>OrderYear SeqNumber Item </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10001 Senior IRS Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10001 IRS Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10002 Senior IRS Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10003 IRS Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10003 Senior IRS Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10003 Jr. Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10004 HOA Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>In addition to the concatenation, I am trying to manipulate the data as follows: </em></p>
<p style="padding-left:60px;text-align:justify;"><em>1) I would like to order the items alphabetically. </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2) I would like to put an “and” before the last concatenation when there are more than 1 Item for each Orderyear and SeqNumber. </em></p>
<p style="padding-left:60px;text-align:justify;"><em>3) I would like to put in a “,” between each concatenation when there are 3 or more Item for each Orderyear and SeqNumber (except in between the last two concatenation. </em></p>
<p style="padding-left:60px;text-align:justify;"><em>4) I would like this data inserted into a temp table called #TSGItems </em></p>
<p style="padding-left:60px;text-align:justify;"><em>When I do a select statement on #TSGItems, I would like the data shown as follow: </em></p>
<p style="padding-left:60px;text-align:justify;"><em>OrderYear SeqNumber Item </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10001 IRS Lien and Senior IRS Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10002 Senior IRS Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10003 Jr. Lien, IRS Lien, and Senior IRS Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>2008 10004 HOA Lien </em></p>
<p style="padding-left:60px;text-align:justify;"><em>I thank you for taking the time to look at and attempt to solve my challenge. </em></p>
<p style="padding-left:60px;text-align:justify;"><em>-Anthony</em></p>
<p style="text-align:justify;">Let us read the answer from Imran from here.</p>
<p style="padding-left:60px;text-align:justify;"><em>@Anthony</em></p>
<p style="padding-left:60px;text-align:justify;"><em>Let me tell you I am not a developer and I dont have much developing skills… I am sure there must be another good way of writing sql code for what you have asked…</em></p>
<p style="padding-left:60px;text-align:justify;"><em>Below is my code, This does exactly what you described in your  post.</em></p>
<p style="padding-left:60px;"><code style="font-size:12px;"><span style="color:blue;">CREATE TABLE </span><span style="color:black;">TGSITEMS </span><span style="color:gray;">( </span><span style="color:black;">ORDERYEAR DATETIME</span><span style="color:gray;">, </span><span style="color:black;">SEQNUMBER </span><span style="color:blue;">INT </span><span style="color:gray;">, </span><span style="color:black;">ITEM </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">))<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:black;">TGSITEMS </span><span style="color:gray;">(</span><span style="color:black;">ORDERYEAR</span><span style="color:gray;">, </span><span style="color:black;">SEQNUMBER</span><span style="color:gray;">, </span><span style="color:black;">ITEM</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'2008' </span><span style="color:gray;">,</span><span style="color:black;">10001 </span><span style="color:gray;">, </span><span style="color:red;">'Senior IRS Lien' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'2008' </span><span style="color:gray;">, </span><span style="color:black;">10001 </span><span style="color:gray;">, </span><span style="color:red;">'IRS Lien' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'2008' </span><span style="color:gray;">, </span><span style="color:black;">10002 </span><span style="color:gray;">, </span><span style="color:red;">'Senior IRS Lien' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'2008' </span><span style="color:gray;">,</span><span style="color:black;">10003</span><span style="color:gray;">, </span><span style="color:red;">'IRS Lien' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'2008' </span><span style="color:gray;">,</span><span style="color:black;">10003 </span><span style="color:gray;">, </span><span style="color:red;">'Senior IRS Lien' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'2008' </span><span style="color:gray;">,</span><span style="color:black;">10003</span><span style="color:gray;">, </span><span style="color:red;">'Jr. Lien' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'2008' </span><span style="color:gray;">,</span><span style="color:black;">10004</span><span style="color:gray;">, </span><span style="color:red;">'HOA Lien' </span></code>
</p>
<p style="padding-left:60px;text-align:justify;"><em>We created a table TGSITEMS and we inserted all the values which you mentioned in your post.</em></p>
<p style="padding-left:60px;text-align:justify;"><em>Then I created two more temporary tables #TGSITEMS and #TGSITEMS1… and with the help of While loop and cursor I got your result.</em></p>
<p style="padding-left:60px;"><code style="font-size:12px;"><span style="color:blue;">CREATE TABLE </span><span style="color:#434343;">#TGSITEMS </span><span style="color:gray;">( </span><span style="color:black;">ORDERYEAR DATETIME</span><span style="color:gray;">, </span><span style="color:black;">SEQNUMBER </span><span style="color:blue;">INT </span><span style="color:gray;">, </span><span style="color:black;">ITEM </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">))<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:#434343;">#TGSITEMS</span><span style="color:black;">1 </span><span style="color:gray;">( </span><span style="color:black;">ID </span><span style="color:blue;">INT </span><span style="color:#434343;">IDENTITY</span><span style="color:gray;">, </span><span style="color:black;">ITEM </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">))<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@VAR </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@CUR </span><span style="color:blue;">CURSOR<br />
DECLARE </span><span style="color:#434343;">@VAR1 </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@CMD </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">1000</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@CMD1 </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">1000</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@CUR </span><span style="color:blue;">= CURSOR FOR<br />
SELECT DISTINCT </span><span style="color:black;">SEQNUMBER<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">TGSITEMS<br />
</span><span style="color:blue;">OPEN </span><span style="color:#434343;">@CUR<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">@CUR </span><span style="color:blue;">INTO </span><span style="color:#434343;">@VAR<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@@FETCH_STATUS </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN<br />
TRUNCATE TABLE </span><span style="color:#434343;">#TGSITEMS</span><span style="color:black;">1<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">#TGSITEMS</span><span style="color:black;">1 </span><span style="color:gray;">(</span><span style="color:black;">ITEM</span><span style="color:gray;">) </span><span style="color:blue;">SELECT </span><span style="color:black;">ITEM </span><span style="color:blue;">FROM </span><span style="color:black;">TGSITEMS </span><span style="color:blue;">WHERE </span><span style="color:black;">SEQNUMBER </span><span style="color:blue;">= </span><span style="color:#434343;">@VAR </span><span style="color:blue;">ORDER BY </span><span style="color:black;">ITEM<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@VAR1 </span><span style="color:blue;">= </span><span style="color:black;">1<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@CMD1 </span><span style="color:blue;">= </span><span style="color:red;">''<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@VAR1 </span><span style="color:gray;">&lt;= ( </span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:blue;">FROM </span><span style="color:#434343;">#TGSITEMS</span><span style="color:black;">1 </span><span style="color:gray;">)<br />
</span><span style="color:blue;">BEGIN<br />
SELECT </span><span style="color:#434343;">@CMD </span><span style="color:blue;">= </span><span style="color:black;">ITEM </span><span style="color:blue;">FROM </span><span style="color:#434343;">#TGSITEMS</span><span style="color:black;">1 </span><span style="color:blue;">WHERE </span><span style="color:black;">ID </span><span style="color:blue;">= </span><span style="color:#434343;">@VAR1<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@VAR1 </span><span style="color:gray;">&lt;(</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:blue;">FROM </span><span style="color:#434343;">#TGSITEMS</span><span style="color:black;">1</span><span style="color:gray;">) -</span><span style="color:black;">1<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@CMD1 </span><span style="color:blue;">= </span><span style="color:#434343;">@CMD1 </span><span style="color:gray;">+ </span><span style="color:#434343;">@CMD </span><span style="color:gray;">+</span><span style="color:red;">' , '<br />
</span><span style="color:blue;">ELSE IF </span><span style="color:#434343;">@VAR1 </span><span style="color:blue;">= </span><span style="color:gray;">(</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:blue;">FROM </span><span style="color:#434343;">#TGSITEMS</span><span style="color:black;">1 </span><span style="color:gray;">)-</span><span style="color:black;">1<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@CMD1 </span><span style="color:blue;">= </span><span style="color:#434343;">@CMD1 </span><span style="color:gray;">+ </span><span style="color:#434343;">@CMD<br />
</span><span style="color:blue;">ELSE IF </span><span style="color:gray;">(</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:blue;">FROM </span><span style="color:#434343;">#TGSITEMS</span><span style="color:black;">1 </span><span style="color:gray;">) </span><span style="color:blue;">= </span><span style="color:black;">1<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@CMD1 </span><span style="color:blue;">= </span><span style="color:#434343;">@CMD<br />
</span><span style="color:blue;">ELSE<br />
SET </span><span style="color:#434343;">@CMD1 </span><span style="color:blue;">= </span><span style="color:#434343;">@CMD1 </span><span style="color:gray;">+ </span><span style="color:red;">' and ' </span><span style="color:gray;">+ </span><span style="color:#434343;">@CMD<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@VAR1 </span><span style="color:blue;">= </span><span style="color:#434343;">@VAR1 </span><span style="color:gray;">+ </span><span style="color:black;">1<br />
</span><span style="color:blue;">END<br />
INSERT INTO </span><span style="color:#434343;">#TGSITEMS </span><span style="color:blue;">SELECT DISTINCT </span><span style="color:black;">ORDERYEAR </span><span style="color:gray;">, </span><span style="color:black;">SEQNUMBER</span><span style="color:gray;">, </span><span style="color:#434343;">@CMD1 </span><span style="color:blue;">FROM </span><span style="color:black;">TGSITEMS </span><span style="color:blue;">WHERE </span><span style="color:black;">SEQNUMBER </span><span style="color:blue;">= </span><span style="color:#434343;">@VAR<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">@CUR </span><span style="color:blue;">INTO </span><span style="color:#434343;">@VAR<br />
</span><span style="color:blue;">END<br />
CLOSE </span><span style="color:#434343;">@CUR<br />
</span><span style="color:blue;">DEALLOCATE </span><span style="color:#434343;">@CUR<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATENAME </span><span style="color:gray;">( </span><span style="color:black;">YY</span><span style="color:gray;">, </span><span style="color:black;">ORDERYEAR</span><span style="color:gray;">)</span><span style="color:black;">ORDERDATE </span><span style="color:gray;">, </span><span style="color:black;">SEQNUMBER</span><span style="color:gray;">, </span><span style="color:black;">ITEM </span><span style="color:blue;">FROM </span><span style="color:#434343;">#TGSITEMS<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">TRUNCATE TABLE </span><span style="color:#434343;">#TGSITEMS<br />
</span><span style="color:black;">GO </span></code>
</p>
<p style="padding-left:60px;text-align:justify;"><em>Let me tell you this is highly performance consuming process… its upto you if you want to use it…</em></p>
<p style="padding-left:60px;text-align:justify;"><em>Hope this helps.<br />
Thanks<br />
Imran.</em>
</p>
<p style="text-align:justify;">It was very good comment from Imran and here is Anthony&#8217;s response to Imran&#8217;s answer.</p>
<p style="padding-left:60px;text-align:justify;"><em>Thank you  Imran,<br />
I really appreciate you taking the time to address this challenge. I have been trying to move away from MS Access and am new to the SQL environment. I agree, what I am asking for is very demanding, but I feel reverting to Access is a step backward. I cannot wait to try the coded at work when I return on Monday.</em></p>
<p style="padding-left:60px;text-align:justify;"><em>Cheers<br />
-Anthony</em>
</p>
<p style="text-align:justify;">I thank you both of you to using this platform for helping solve technical problems.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<p style="padding-left:60px;text-align:justify;">
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/687/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/687/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/687/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=687&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/07/16/sql-server-readers-contribution-to-site-simple-example-of-cursor/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Is Cursor Database Object or Datatype</title>
		<link>http://blog.sqlauthority.com/2008/04/19/sql-server-is-cursor-database-object-or-datatype/</link>
		<comments>http://blog.sqlauthority.com/2008/04/19/sql-server-is-cursor-database-object-or-datatype/#comments</comments>
		<pubDate>Sat, 19 Apr 2008 01:30:29 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=575</guid>
		<description><![CDATA[It is commonly believed that cursor are Database Objects. I have always given the definition of cursor as SQL Server cursors are database objects used to manipulate data in a set on a row-by-row basis.
Just a few days ago &#8211; Imran one of the active reader of blog asked me question if cursor is database [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=575&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">It is commonly believed that cursor are Database Objects. I have always given the definition of cursor as SQL Server cursors are database objects used to manipulate data in a set on a row-by-row basis.</p>
<p style="text-align:justify;">Just a few days ago &#8211; Imran one of the active reader of blog asked me question <strong>if cursor is database object or datatype?</strong> My answer to this question is Cursor is Database Object. However, this question is very very interesting. We define cursor same was as datatypes using DECLARE statement and it can be used same way as any other datatypes.</p>
<p style="text-align:justify;"><em>I would like to see all of your opinion about what do you think about cursor? Database Object or Database Datatype.</em></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/575/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/575/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/575/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=575&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/04/19/sql-server-is-cursor-database-object-or-datatype/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Simple Example of Cursor &#8211; Sample Cursor Part 2</title>
		<link>http://blog.sqlauthority.com/2008/03/05/sql-server-simple-example-of-cursor-sample-cursor-part-2/</link>
		<comments>http://blog.sqlauthority.com/2008/03/05/sql-server-simple-example-of-cursor-sample-cursor-part-2/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 01:30:10 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=527</guid>
		<description><![CDATA[I have recently received email that I should update SQL SERVER &#8211; Simple Example of Cursor with example of AdventureWorks database.
Simple Example of Cursor using AdventureWorks Database is listed here.

USE AdventureWorks
GO
DECLARE @ProductID INT
DECLARE @getProductID CURSOR
SET @getProductID = CURSOR FOR
SELECT ProductID
FROM Production.Product
OPEN @getProductID
FETCH NEXT
FROM @getProductID INTO @ProductID
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @ProductID
FETCH NEXT
FROM @getProductID INTO @ProductID
END
CLOSE @getProductID
DEALLOCATE @getProductID
GO

Reference : [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=527&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I have recently received email that I should update <a href="http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/" target="_blank">SQL SERVER &#8211; Simple Example of Cursor</a> with example of AdventureWorks database.</p>
<p style="text-align:justify;">Simple Example of Cursor using AdventureWorks Database is listed here.<br />
<code style="font-size:12px;"><span style="color:black;"><br />
</span></code><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@ProductID </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@getProductID </span><span style="color:blue;">CURSOR<br />
SET </span><span style="color:#434343;">@getProductID </span><span style="color:blue;">= CURSOR FOR<br />
SELECT </span><span style="color:black;">ProductID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Production.Product<br />
</span><span style="color:blue;">OPEN </span><span style="color:#434343;">@getProductID<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">@getProductID </span><span style="color:blue;">INTO </span><span style="color:#434343;">@ProductID<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@@FETCH_STATUS </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN<br />
PRINT </span><span style="color:#434343;">@ProductID<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">@getProductID </span><span style="color:blue;">INTO </span><span style="color:#434343;">@ProductID<br />
</span><span style="color:blue;">END<br />
CLOSE </span><span style="color:#434343;">@getProductID<br />
</span><span style="color:blue;">DEALLOCATE </span><span style="color:#434343;">@getProductID<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><code style="font-size:12px;"></code><br />
Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/527/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/527/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/527/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=527&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/03/05/sql-server-simple-example-of-cursor-sample-cursor-part-2/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQLAuthority News &#8211; Best Articles on SQLAuthority.com</title>
		<link>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/</link>
		<comments>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/#comments</comments>
		<pubDate>Sun, 04 Nov 2007 14:00:25 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Data Warehousing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Add-On]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Backup and Restore]]></category>
		<category><![CDATA[SQL Coding Standards]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Error Messages]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Humor]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/</guid>
		<description><![CDATA[SQL SERVER &#8211; Cursor to Kill All Process in Database
SQL SERVER &#8211; Find Stored Procedure Related to Table in Database &#8211; Search in All Stored procedure
SQL SERVER &#8211; Shrinking Truncate Log File &#8211; Log Full
SQL SERVER &#8211; Simple Example of Cursor
SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=395&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/01/sql-server-cursor-to-kill-all-process-in-database/">SQL SERVER &#8211; Cursor to Kill All Process in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/10/sql-server-find-stored-procedure-related-to-table-in-database-search-in-all-stored-procedure/">SQL SERVER &#8211; Find Stored Procedure Related to Table in Database &#8211; Search in All Stored procedure</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/">SQL SERVER &#8211; Shrinking Truncate Log File &#8211; Log Full</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/">SQL SERVER &#8211; Simple Example of Cursor</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/">SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper Case</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/25/sql-server-restore-database-backup-using-sql-script-t-sql/">SQL SERVER &#8211; Restore Database Backup using SQL Script (T-SQL)</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/28/sql-server-t-sql-script-to-find-the-cd-key-from-registry/">SQL SERVER &#8211; T-SQL Script to find the CD key from Registry</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/">SQL SERVER &#8211; Delete Duplicate Records &#8211; Rows</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/05/sql-server-quoted_identifier-onoff-and-ansi_null-onoff-explanation/">SQL SERVER &#8211; QUOTED_IDENTIFIER ON/OFF and ANSI_NULL ON/OFF Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/10/sql-server-union-vs-union-all-which-is-better-for-performance/">SQL SERVER &#8211; Union vs. Union All &#8211; Which is better for performance?</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/15/sql-server-dbcc-reseed-table-identity-value-reset-table-identity/">SQL SERVER &#8211; DBCC RESEED Table Identity Value &#8211; Reset Table Identity</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/">SQL SERVER &#8211; @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT &#8211; Retrieve Last Inserted Identity of Record</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/29/sql-server-difference-between-distinct-and-group-by-distinct-vs-group-by/">SQL SERVER &#8211; Difference between DISTINCT and GROUP BY &#8211; Distinct vs Group By</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/30/sql-server-index-seek-vs-index-scan-table-scan/">SQL SERVER &#8211; Index Seek Vs. Index Scan (Table Scan)</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/01/sql-server-tempdb-is-full-move-tempdb-from-one-drive-to-another-drive/">SQL SERVER &#8211; TempDB is Full. Move TempDB from one drive to another drive</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/03/sql-server-t-sql-paging-query-technique-comparison-sql-2000-vs-sql-2005/">SQL SERVER &#8211; T-SQL Paging Query Technique Comparison &#8211; SQL 2000 vs SQL 2005</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/05/sql-server-performance-optimization-of-sql-query-and-filegroups/">SQL SERVER &#8211; Performance Optimization of SQL Query and FileGroups</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/08/sql-server-search-text-field-charindex-vs-patindex/">SQL SERVER &#8211; Search Text Field &#8211; CHARINDEX vs PATINDEX</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/">SQL SERVER &#8211; 2005 Explanation of TRY…CATCH and ERROR Handling</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/13/sql-server-script-to-find-sql-server-on-network/">SQL SERVER &#8211; Script to find SQL Server on Network</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/13/sql-server-stored-procedures-advantages-and-best-advantage/">SQL SERVER &#8211; Stored Procedures Advantages and Best Advantage</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/">SQL SERVER &#8211; CASE Statement/Expression Examples and Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/22/sql-server-raid-configuration-raid-10/">SQL SERVER &#8211; Raid Configuration &#8211; RAID 10</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/23/sql-server-understanding-new-index-type-of-sql-server-2005-included-column-index-along-with-clustered-index-and-non-clustered-index/">SQL SERVER &#8211; Understanding new Index Type of SQL Server 2005 Included Column Index along with Clustered Index and Non-clustered Index</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/23/sql-server-query-to-find-seed-values-increment-values-and-current-identity-column-value-of-the-table/">SQL SERVER &#8211; Query to Find Seed Values, Increment Values and Current Identity Column value of the table</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/24/sql-server-six-properties-of-relational-tables/">SQL SERVER &#8211; Six Properties of Relational Tables</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/24/sql-server-trim-function-udf-trim/">SQL SERVER &#8211; TRIM() Function &#8211; UDF TRIM()</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/26/sql-server-difference-between-unique-index-vs-unique-constraint/">SQL SERVER &#8211; Difference between Unique Index vs Unique Constraint</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/27/sql-server-2005-locking-hints-and-examples/">SQL SERVER &#8211; 2005 Locking Hints and Examples</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/28/sql-server-good-better-and-best-programming-techniques/">SQL SERVER &#8211; Good, Better and Best Programming Techniques</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/">SQL SERVER &#8211; Random Number Generator Script &#8211; SQL Query</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/02/sql-server-2005-top-improvementsenhancements/">SQL SERVER &#8211; 2005 TOP Improvements/Enhancements</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/07/sql-server-20052000-examples-and-explanation-for-goto/">SQL SERVER &#8211; 2005/2000 Examples and Explanation for GOTO</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/11/sql-server-explanation-sql-command-go/">SQL SERVER &#8211; Explanation SQL Commando GO</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/12/sql-server-2005-list-all-the-database/">SQL SERVER &#8211; 2005 &#8211; List all the database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/">SQL SERVER &#8211; UDF &#8211; Function to Parse AlphaNumeric Characters from String</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/17/sql-server-disable-index-enable-index-alter-index/">SQL SERVER &#8211; Disable Index &#8211; Enable Index &#8211; ALTER Index</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/18/sql-server-2005-ssms-change-t-sql-batch-separator/">SQL SERVER &#8211; 2005 &#8211; SSMS Change T-SQL Batch Separator</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/20/sql-server-sql-code-formatter-tools/">SQL SERVER &#8211; SQL Code Formatter Tools</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/">SQL SERVER &#8211; 2005 Comparison EXCEPT operator vs. NOT IN</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/23/sql-server-2005-northwind-database-or-adventureworks-database-samples-databases/">SQL SERVER &#8211; 2005 NorthWind Database or AdventureWorks Database &#8211; Samples Databases</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/26/sql-server-2005-find-table-without-clustered-index-find-table-with-no-primary-key/">SQL SERVER &#8211; 2005 Find Table without Clustered Index &#8211; Find Table with no Primary Key</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/27/sql-server-2005-limiting-result-sets-by-using-tablesample-examples/">SQL SERVER &#8211; 2005 Limiting Result Sets by Using TABLESAMPLE &#8211; Examples</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/29/sql-server-2005-change-database-compatible-level-backward-compatibility/">SQL SERVER &#8211; 2005 Change Database Compatible Level &#8211; Backward Compatibility</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/01/sql-server-2005-constraint-on-varcharmax-field-to-limit-it-certain-length/">SQL SERVER &#8211; 2005 Constraint on VARCHAR(MAX) Field To Limit It Certain Length</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/06/sql-server-database-coding-standards-and-guidelines-complete-list-download/">SQL SERVER Database Coding Standards and Guidelines Complete List Download</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/">SQL SERVER &#8211; Insert Multiple Records Using One Insert Statement &#8211; Use of UNION ALL</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/">SQL SERVER &#8211; Retrieve &#8211; Select Only Date Part From DateTime &#8211; Best Practice</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/11/sql-server-2005-t-sql-paging-query-technique-comparison-over-and-row_number-cte-vs-derived-table/">SQL SERVER &#8211; 2005 T-SQL Paging Query Technique Comparison (OVER and ROW_NUMBER()) &#8211; CTE vs. Derived Table</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/14/sql-server-easy-sequence-of-select-from-join-where-group-by-having-order-by/">SQL SERVER &#8211; Easy Sequence of SELECT FROM JOIN WHERE GROUP BY HAVING ORDER BY</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/">SQL SERVER &#8211; 2005 &#8211; UDF &#8211; User Defined Function to Strip HTML &#8211; Parse HTML &#8211; No Regular Expression</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/21/sql-server-retrieve-current-date-time-in-sql-server-current_timestamp-getdate-fn-now/">SQL SERVER &#8211; Retrieve Current Date Time in SQL Server CURRENT_TIMESTAMP, GETDATE(), {fn NOW()}</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/22/sql-server-explanation-and-comparison-of-nullif-and-isnull/">SQL SERVER &#8211; Explanation and Comparison of NULLIF and ISNULL</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/23/sql-server-2005-row-overflow-data-explanation/">SQL SERVER &#8211; 2005 Row Overflow Data Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/24/sql-server-comparison-index-fragmentation-index-de-fragmentation-index-rebuild-sql-server-2000-and-sql-server-2005/">SQL SERVER &#8211; Comparison Index Fragmentation, Index De-Fragmentation, Index Rebuild &#8211; SQL SERVER 2000 and SQL SERVER 2005</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/03/sql-server-comparison-similarity-and-difference-temptable-vs-tempvariable/">SQL SERVER &#8211; Comparison : Similarity and Difference #TempTable vs @TempVariable</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/04/sql-server-definition-comparison-and-difference-between-having-and-where-clause/">SQL SERVER &#8211; Definition, Comparison and Difference between HAVING and WHERE Clause</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/05/sql-server-2005-best-practices-analyzer-tutorial-sample-example/">SQL SERVER &#8211; 2005 Best Practices Analyzer Tutorial &#8211; Sample Example</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/10/sql-server-2005-list-all-stored-procedure-modified-in-last-n-days/">SQL SERVER &#8211; 2005 &#8211; List All Stored Procedure Modified in Last N Days</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/11/sql-server-count-duplicate-records-rows/">SQL SERVER &#8211; Count Duplicate Records &#8211; Rows</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/17/sql-server-case-statement-in-order-by-clause-order-by-using-variable/">SQL SERVER &#8211; CASE Statement in ORDER BY Clause &#8211; ORDER BY using Variable</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/18/sql-server-restore-database-without-or-with-backup-everything-about-restore-and-backup/">SQL SERVER &#8211; Restore Database Without or With Backup &#8211; Everything About Restore and Backup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/23/sql-server-udf-function-to-get-previous-and-next-work-day-exclude-saturday-and-sunday/">SQL SERVER &#8211; UDF &#8211; Function to Get Previous And Next Work Day &#8211; Exclude Saturday and Sunday</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/04/sql-server-one-thing-all-dba-must-know/">SQL SERVER &#8211; One Thing All DBA Must Know</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/07/sql-server-2005-list-tables-in-database-without-primary-key/">SQL SERVER &#8211; 2005 &#8211; List Tables in Database Without Primary Key</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/10/sql-server-2005-find-stored-procedure-create-date-and-modified-date/">SQL SERVER &#8211; 2005 &#8211; Find Stored Procedure Create Date and Modified Date</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/11/sql-server-udf-validate-integer-function/">SQL SERVER &#8211; UDF &#8211; Validate Integer Function</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/14/sql-server-what-is-sql-how-to-pronounce-sql/">SQL SERVER &#8211; What is SQL? How to pronounce SQL?</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/16/sql-server-2005-difference-and-similarity-between-newsequentialid-and-newid/">SQL SERVER &#8211; 2005 &#8211; Difference and Similarity Between NEWSEQUENTIALID() and NEWID()</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/17/sql-server-2005-explanation-and-script-for-online-index-operations-create-rebuild-drop/">SQL SERVER &#8211; 2005 &#8211; Explanation and Script for Online Index Operations &#8211; Create, Rebuild, Drop</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/18/sql-server-find-last-day-of-any-month-current-previous-next/">SQL SERVER &#8211; Find Last Day of Any Month &#8211; Current Previous Next</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/">SQL SERVER &#8211; T-SQL Script to Insert Carriage Return and New Line Feed in Code</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/24/sql-server-2005-t-sql-script-to-attach-and-detach-database/">SQL SERVER &#8211; 2005 &#8211; T-SQL Script to Attach and Detach Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/28/sql-server-actual-execution-plan-vs-estimated-execution-plan/">SQL SERVER &#8211; Actual Execution Plan vs. Estimated Execution Plan</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/03/sql-server-2005-search-stored-procedure-code-search-stored-procedure-text/">SQL SERVER &#8211; 2005 &#8211; Search Stored Procedure Code &#8211; Search Stored Procedure Text</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-primary-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; Find Tables With Primary Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/06/sql-server-2005-introduction-and-explanation-to-sqlcmd/">SQL SERVER &#8211; 2005 &#8211; Introduction and Explanation to sqlcmd</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/">SQL SERVER &#8211; UDF &#8211; User Defined Function &#8211; Get Number of Days in Month</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/09/sql-server-2005-start-stop-restart-sql-server-from-command-prompt/">SQL SERVER &#8211; 2005 &#8211; Start Stop Restart SQL Server From Command Prompt</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/16/sql-server-2005-list-all-the-constraint-of-database-find-primary-key-and-foreign-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; List All The Constraint of Database &#8211; Find Primary Key and Foreign Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/18/sql-server-udf-validate-positive-integer-function-validate-natural-integer-function/">SQL SERVER &#8211; UDF &#8211; Validate Positive Integer Function &#8211; Validate Natural Integer Function</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/25/sql-server-effect-of-transaction-on-local-variable-after-rollback-and-after-commit/">SQL SERVER &#8211; Effect of TRANSACTION on Local Variable &#8211; After ROLLBACK and After COMMIT</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/01/sql-server-2005-output-clause-example-and-explanation-with-insert-update-delete/">SQL SERVER &#8211; 2005 &#8211; OUTPUT Clause Example and Explanation with INSERT, UPDATE, DELETE</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/09/sql-server-2005-sample-example-of-ranking-functions-row_number-rank-dense_rank-ntile/">SQL SERVER &#8211; 2005 &#8211; Sample Example of RANKING Functions &#8211; ROW_NUMBER, RANK, DENSE_RANK, NTILE</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/16/sql-server-three-t-sql-script-to-create-primary-keys-on-table/">SQL SERVER &#8211; Three T-SQL Script to Create Primary Keys on Table</a></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/395/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/395/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/395/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=395&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Simple Example of WHILE Loop With CONTINUE and BREAK Keywords</title>
		<link>http://blog.sqlauthority.com/2007/10/24/sql-server-simple-example-of-while-loop-with-continue-and-break-keywords/</link>
		<comments>http://blog.sqlauthority.com/2007/10/24/sql-server-simple-example-of-while-loop-with-continue-and-break-keywords/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 14:00:13 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/10/24/sql-server-simple-example-of-while-loop-with-continue-and-break-keywords/</guid>
		<description><![CDATA[This is question is one of those question which is very simple and most of the users get it correct, however few users find it confusing for first time. I have tried to explain the usage of simple WHILE loop in first example. BREAK keyword will exit the stop the while loop and control is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=361&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This is question is one of those question which is very simple and most of the users get it correct, however few users find it confusing for first time. I have tried to explain the usage of simple WHILE loop in first example. BREAK keyword will exit the stop the while loop and control is moved to next statement after the while loop. CONTINUE keyword skips all the statement after its execution and control is sent to first statement of while loop. Run following examples in Query Editor and see the result. This is very easy to understand example.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">1) Example of WHILE Loop</span><br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">= </span><span style="color:black;">1<br />
</span><span style="color:blue;">WHILE </span><span style="color:gray;">(</span><span style="color:#434343;">@intFlag </span><span style="color:gray;">&lt;=</span><span style="color:black;">5</span><span style="color:gray;">)<br />
</span><span style="color:blue;">BEGIN<br />
PRINT </span><span style="color:#434343;">@intFlag<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">= </span><span style="color:#434343;">@intFlag </span><span style="color:gray;">+ </span><span style="color:black;">1<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<span style="font-weight:bold;">ResultSet:</span><br />
1<br />
2<br />
3<br />
4<br />
5</p>
<p style="text-align:justify;"><span style="font-weight:bold;">2) Example of WHILE Loop with BREAK keyword</span><br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">= </span><span style="color:black;">1<br />
</span><span style="color:blue;">WHILE </span><span style="color:gray;">(</span><span style="color:#434343;">@intFlag </span><span style="color:gray;">&lt;=</span><span style="color:black;">5</span><span style="color:gray;">)<br />
</span><span style="color:blue;">BEGIN<br />
PRINT </span><span style="color:#434343;">@intFlag<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">= </span><span style="color:#434343;">@intFlag </span><span style="color:gray;">+ </span><span style="color:black;">1<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">= </span><span style="color:black;">4<br />
</span><span style="color:blue;">BREAK</span><span style="color:gray;">;<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<span style="font-weight:bold;">ResultSet:</span><br />
1<br />
2<br />
3</p>
<p style="text-align:justify;"><span style="font-weight:bold;">3) Example of WHILE Loop with CONTINUE and BREAK keywords</span><br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">= </span><span style="color:black;">1<br />
</span><span style="color:blue;">WHILE </span><span style="color:gray;">(</span><span style="color:#434343;">@intFlag </span><span style="color:gray;">&lt;=</span><span style="color:black;">5</span><span style="color:gray;">)<br />
</span><span style="color:blue;">BEGIN<br />
PRINT </span><span style="color:#434343;">@intFlag<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">= </span><span style="color:#434343;">@intFlag </span><span style="color:gray;">+ </span><span style="color:black;">1<br />
</span><span style="color:blue;">CONTINUE</span><span style="color:gray;">;<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@intFlag </span><span style="color:blue;">= </span><span style="color:black;">4 </span><span style="color:green;">-- This will never executed<br />
</span><span style="color:blue;">BREAK</span><span style="color:gray;">;<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<span style="font-weight:bold;">ResultSet:</span><br />
1<br />
2<br />
3<br />
4<br />
5
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/361/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/361/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/361/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=361&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/10/24/sql-server-simple-example-of-while-loop-with-continue-and-break-keywords/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Stored Procedure to Know Database Access Permission to Current User</title>
		<link>http://blog.sqlauthority.com/2007/09/23/sql-server-stored-procedure-to-know-database-access-permission-to-current-user/</link>
		<comments>http://blog.sqlauthority.com/2007/09/23/sql-server-stored-procedure-to-know-database-access-permission-to-current-user/#comments</comments>
		<pubDate>Sun, 23 Sep 2007 14:00:49 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[undocumented SQL]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/23/sql-server-stored-procedure-to-know-database-access-permission-to-current-user/</guid>
		<description><![CDATA[Jr. DBA in my company only have access to the database which they need to use. Often they try to access database and if they do not have permission they face error. Jr. DBAs always check which database they have access using following system stored procedure. It is very reliable and provides accurate information.
Sytanx:
EXEC sp_MShasdbaccess
GO

ResultSet: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=344&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Jr. DBA in my company only have access to the database which they need to use. Often they try to access database and if they do not have permission they face error. Jr. DBAs always check which database they have access using following system stored procedure. It is very reliable and provides accurate information.</p>
<p style="text-align:justify;"><strong>Sytanx:</strong><br />
<code style="font-size:12px;"><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_MShasdbaccess<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<strong>ResultSet:</strong> ( I have listed only one column)<br />
AdventureWorks<br />
AdventureWorksDW<br />
master<br />
model<br />
msdb<br />
MyDB<br />
ReportServer<br />
ReportServerTempDB<br />
tempdb
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/344/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/344/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/344/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=344&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/09/23/sql-server-stored-procedure-to-know-database-access-permission-to-current-user/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Difference Between EXEC and EXECUTE vs EXEC() &#8211; Use EXEC/EXECUTE for SP always</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/</link>
		<comments>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 14:00:36 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Dynamic SQL]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/</guid>
		<description><![CDATA[What is the difference between EXEC and EXECUTE?
They are the same. Both of them executes stored procedure when called as
EXEC sp_help
GO
EXECUTE sp_help
GO

I have seen enough times developer getting confused between EXEC and EXEC(). EXEC command executes stored procedure where as EXEC() function takes dynamic string as input and executes them.
EXEC('EXEC sp_help')
GO

Another common mistakes I have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=263&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><strong><em>What is the difference between EXEC and EXECUTE?</em></strong></p>
<p style="text-align:justify;">They are the same. Both of them executes stored procedure when called as<br />
<code style="font-size:12px;"><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_help<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">EXECUTE </span><span style="color:darkred;">sp_help<br />
</span><span style="color:black;">GO<br />
</span></code><br />
I have seen enough times developer getting confused between EXEC and EXEC(). EXEC command executes stored procedure where as EXEC() function takes dynamic string as input and executes them.<br />
<code style="font-size:12px;"><span style="color:blue;">EXEC</span><span style="color:gray;">(</span><span style="color:red;">'EXEC sp_help'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code><br />
Another common mistakes I have seen is <em>not using EXEC before stored procedure</em>. It is always good practice to use EXEC before stored procedure name even though SQL Server assumes any command as stored procedure when it does not recognize the first statement. Developer learns while working with Query Editor in SSMS that EXEC is not necessary before running any stored procedure. However, consider following two test and you will see why EXEC or EXECUTE is necessary in many cases and good practice to use it.</p>
<p style="text-align:justify;"><strong>TEST 1 : No Errors</strong><br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">----Try this first independently this will throw an error<br />
</span><span style="color:darkred;">sp_helptext </span><span style="color:red;">'dbo.uspPrintError'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">----Try this second independently this will work fine<br />
</span><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_helptext </span><span style="color:red;">'dbo.uspPrintError'<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<strong>TEST 2 : EXEC prevents error</strong><br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">----Try this first independently this will throw an error<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Sales.Individual<br />
</span><span style="color:darkred;">sp_helptext </span><span style="color:red;">'dbo.uspPrintError'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">----Try this second independently this will work fine<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Sales.Individual<br />
</span><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_helptext </span><span style="color:red;">'dbo.uspPrintError'<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<em><strong>Test 2 indicates that using EXEC or EXECUTE is good practice as it always executes the stored procedure, when not using EXEC can confuse SQL SERVER to misinterpret commands and may create errors.</strong></em>
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/263/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/263/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/263/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=263&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 &#8211; Search Stored Procedure Code &#8211; Search Stored Procedure Text</title>
		<link>http://blog.sqlauthority.com/2007/09/03/sql-server-2005-search-stored-procedure-code-search-stored-procedure-text/</link>
		<comments>http://blog.sqlauthority.com/2007/09/03/sql-server-2005-search-stored-procedure-code-search-stored-procedure-text/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 14:00:57 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/03/sql-server-2005-search-stored-procedure-code-search-stored-procedure-text/</guid>
		<description><![CDATA[I receive following question many times by my team members.
How can I find if particular table is being used in the stored procedure?
How to search in stored procedures?
How can I do dependency check for objects in stored procedure without using sp_depends?

I have previously wrote article about this SQL SERVER &#8211; Find Stored Procedure Related to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=321&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I receive following question many times by my team members.</p>
<p style="text-align:justify;">How can I find if particular table is being used in the stored procedure?<br />
How to search in stored procedures?<br />
How can I do dependency check for objects in stored procedure without using sp_depends?
</p>
<p style="text-align:justify;">I have previously wrote article about this <a href="http://blog.sqlauthority.com/2006/12/10/sql-server-find-stored-procedure-related-to-table-in-database-search-in-all-stored-procedure/" target="_blank">SQL SERVER &#8211; Find Stored Procedure Related to Table in Database &#8211; Search in All Stored procedure</a>.</p>
<p style="text-align:justify;">The same feature can be implemented using following script in SQL Server 2005.<br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">--Searching for Empoloyee table<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">Name<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.procedures<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">OBJECT_DEFINITION</span><span style="color:gray;">(</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">) LIKE </span><span style="color:red;">'%Employee%'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">--Searching for Empoloyee table and RateChangeDate column together<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">Name<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.procedures<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">OBJECT_DEFINITION</span><span style="color:gray;">(</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">) LIKE </span><span style="color:red;">'%Employee%'<br />
</span><span style="color:gray;">AND </span><span style="color:black;">OBJECT_DEFINITION</span><span style="color:gray;">(</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">) LIKE </span><span style="color:red;">'%RateChangeDate%'<br />
</span><span style="color:black;">GO</span></code><br />
<em><strong>ResultSet:</strong></em><br />
Name<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
uspGetEmployeeManagers<br />
uspGetManagerEmployees<br />
uspUpdateEmployeeHireInfo<br />
uspUpdateEmployeeLogin<br />
uspUpdateEmployeePersonalInfo</p>
<p style="text-align:justify;">Name<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
uspUpdateEmployeeHireInfo
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/321/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/321/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/321/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=321&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/09/03/sql-server-2005-search-stored-procedure-code-search-stored-procedure-text/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 &#8211; Create Script to Copy Database Schema and All The Objects &#8211; Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects</title>
		<link>http://blog.sqlauthority.com/2007/08/21/sql-server-2005-create-script-to-copy-database-schema-and-all-the-objects-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/</link>
		<comments>http://blog.sqlauthority.com/2007/08/21/sql-server-2005-create-script-to-copy-database-schema-and-all-the-objects-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 14:00:39 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Backup and Restore]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/08/21/sql-server-2005-create-script-to-copy-database-schema-and-all-the-objects-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/</guid>
		<description><![CDATA[Following quick tutorial demonstrates how to create T-SQL script to copy complete database schema and all of its objects such as Stored Procedure, Functions, Triggers, Tables, Views, Constraints etc. You can review your schema, backup for reference or use it to compare with previous backup.
Step 1 : Start 

Step 2 : Welcome Screen



Step 3 : [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=302&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Following quick tutorial demonstrates how to create T-SQL script to copy complete database schema and all of its objects such as Stored Procedure, Functions, Triggers, Tables, Views, Constraints etc. You can review your schema, backup for reference or use it to compare with previous backup.</p>
<p style="text-align:justify;"><strong>Step 1 : Start </strong></p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/databasecopy1.gif" alt="" /></p>
<p style="text-align:justify;"><strong>Step 2 : Welcome Screen<br />
</strong>
</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/databasecopy2.gif" alt="" width="493" height="449" /></p>
<p style="text-align:justify;"><strong>Step 3 : Select One or Multiple Database</strong><br />
If Script all objects in the selected database checkbox is not selected it will give options to selected individual objects on respective screen. (e.g. Stored Procedure, Triggers and all other object will have their own screen where they can be selected)
</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/databasecopy3.gif" alt="" width="493" height="449" /></p>
<p style="text-align:justify;"><strong>Step 4 : Select database options</strong></p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/databasecopy4.gif" alt="" width="493" height="449" /></p>
<p style="text-align:justify;"><strong>Step 5 : Select output option</strong></p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/databasecopy5.gif" alt="" width="493" height="449" /></p>
<p style="text-align:justify;"><strong>Step 6 : Review Summary</strong></p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/databasecopy6.gif" alt="" /></p>
<p style="text-align:justify;"><strong>Step 7 : Observe script generation process </strong></p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/databasecopy7.gif" alt="" width="493" height="449" /></p>
<p style="text-align:justify;"><strong>Step 8 : Database object script generation completed in new query window</strong></p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/databasecopy8.gif" alt="" /></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong>, All images are protected by copyright owner SQLAuthority.com</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/302/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/302/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/302/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=302&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/08/21/sql-server-2005-create-script-to-copy-database-schema-and-all-the-objects-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/feed/</wfw:commentRss>
		<slash:comments>306</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/blogfolder/databasecopy1.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/databasecopy2.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/databasecopy3.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/databasecopy4.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/databasecopy5.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/databasecopy6.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/databasecopy7.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/databasecopy8.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 Comparison SP_EXECUTESQL vs EXECUTE/EXEC</title>
		<link>http://blog.sqlauthority.com/2007/07/02/sql-server-2005-comparison-sp_executesql-vs-executeexec/</link>
		<comments>http://blog.sqlauthority.com/2007/07/02/sql-server-2005-comparison-sp_executesql-vs-executeexec/#comments</comments>
		<pubDate>Mon, 02 Jul 2007 14:00:43 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/07/02/sql-server-2005-comparison-sp_executesql-vs-executeexec/</guid>
		<description><![CDATA[Common Properties of SP_EXECUTESQL and EXECUTE/EXEC

 The Transact-SQL statements in the sp_executesql or EXECUTE string are not compiled into an execution plan until sp_executesql or the EXECUTE statement are executed. The strings are not parsed or checked for errors until they are executed. The names referenced in the strings are not resolved until they are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=105&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><span style="font-weight:bold;">Common Properties of SP_EXECUTESQL and EXECUTE</span><strong>/EXEC</strong></p>
<ul style="text-align:justify;">
<li> The Transact-SQL statements in the sp_executesql or EXECUTE string are not compiled into an execution plan until sp_executesql or the EXECUTE statement are executed. The strings are not parsed or checked for errors until they are executed. The names referenced in the strings are not resolved until they are executed.</li>
<li> The Transact-SQL statements in the executed string do not have access to any of the variables declared in the batch that contains thesp_executesql or EXECUTE statement. The batch containing the sp_executesql or EXECUTE statement does not have access to variables or local cursors defined in the executed string.</li>
<li> If the executed string has a USE statement that changes the database context, the change to the database context only lasts untilsp_executesql or the EXECUTE statement completes.</li>
</ul>
<p style="text-align:justify;"><strong>Comparison </strong><span style="font-weight:bold;">SP_EXECUTESQL</span><strong> vs EXECUTE/EXEC</strong></p>
<p style="text-align:justify;">sp_executesql gives you the possibility to use parameterised statements, EXECUTE does not. Parameterised statements gives no risk to SQL injection and also gives advantage of cached query plan. The sp_executesql stored procedure supports parameters. So, using the sp_executesql stored procedure instead of the EXECUTE statement improve readability of your code when there are many parameters are used. When you use thesp_executesql stored procedure to executes a Transact-SQL statements that will be reused many times, the SQL Server query optimizer will reuse the execution plan it generates for the first execution when the change in parameter values to the statement is the only variation.</p>
<p style="text-align:justify;">sp_executesql can be used instead of stored procedures to execute a Transact-SQL statement a number of times when the change in parameter values to the statement is the only variation. Because the Transact-SQL statement itself remains constant and only the parameter values change, the SQL Server query optimizer is likely to reuse the execution plan it generates for the first execution.</p>
<p style="text-align:justify;"><span style="font-weight:bold;font-style:italic;"> Use </span><em><span style="font-weight:bold;">SP_EXECUTESQL</span></em><span style="font-weight:bold;font-style:italic;"> rather than EXEC(), it has better performance and improved security.</span></p>
<p style="text-align:justify;">The syntax for sp_executesql for SQL Server 2005 is<br />
<code style="font-size:12px;"><span style="color:darkred;">sp_executesql </span><span style="color:black;">[ @stmt = ] stmt<br />
[<br />
{, [@params=] </span><span style="color:red;">N'@parameter_name data_type [ OUT | OUTPUT ][,...n]' </span><span style="color:black;">}<br />
{</span><span style="color:gray;">, </span><span style="color:black;">[ @param1 = ] </span><span style="color:red;">'value1' </span><span style="color:black;">[ ,...n ] }<br />
]</span></code><br />
The size of the string is limited only by available database server memory. On 64-bit servers, the size of the string is limited to 2 GB, the maximum size of nvarchar(max).
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/105/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/105/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=105&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/07/02/sql-server-2005-comparison-sp_executesql-vs-executeexec/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; SET ROWCOUNT &#8211; Retrieving or Limiting the First N Records from a SQL Query</title>
		<link>http://blog.sqlauthority.com/2007/04/30/sql-server-set-rowcount-retrieving-or-limiting-the-first-n-records-from-a-sql-query/</link>
		<comments>http://blog.sqlauthority.com/2007/04/30/sql-server-set-rowcount-retrieving-or-limiting-the-first-n-records-from-a-sql-query/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 14:00:26 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/30/set-rowcount-retrieving-or-limiting-the-first-n-records-from-a-sql-query/</guid>
		<description><![CDATA[A SET ROWCOUNT statement simply limits the number of records returned to the client during a single connection. As soon as the number of rows specified is found, SQL Server stops processing the query. The syntax looks like this:
SET ROWCOUNT 10
SELECT *
FROM dbo.Orders
WHERE EmployeeID = 5
ORDER BY OrderDate
SET ROWCOUNT 0
To set this option off so [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=57&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">A SET ROWCOUNT statement simply limits the number of records returned to the client during a single connection. As soon as the number of rows specified is found, SQL Server stops processing the query. The syntax looks like this:<br />
<code style="font-size:12px;"><span style="color:blue;">SET </span><span style="color:#434343;">ROWCOUNT </span><span style="color:black;">10<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.Orders<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">5<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">OrderDate<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">ROWCOUNT </span><span style="color:black;">0</span></code><br />
To set this option off so that all rows are returned, specify SET ROWCOUNT 0.</p>
<p style="text-align:justify;"><strong>When does it work?</strong><br />
SET ROWCOUNT option is ignored for INSERT, UPDATE, and DELETE statements against remote tables and local, remote partitioned views and when an explicit TOP expression is used in the same statement. This includes statements in which INSERT is followed by a SELECT clause. SET ROWCOUNT overrides the SELECT statement TOP keyword if the rowcount is the smaller value.</p>
<p style="text-align:justify;"><strong>How does it work?</strong><br />
Setting the SET ROWCOUNT option causes most Transact-SQL statements to stop processing when they have been affected by the specified number of rows. This includes triggers and data modification statements such as INSERT, UPDATE, and DELETE. The ROWCOUNT option does not affect dynamic cursors, but it does limit the rowset of keyset and insensitive cursors. This option should be used with caution and primarily with the SELECT statement. The setting of SET ROWCOUNT is set at execute or run time and not at parse time.</p>
<p style="text-align:justify;"><strong>Interesting Facts:</strong><br />
Though SET ROWCOUNT n cannot be used in a UDF, the current ROWCOUNT limit setting of its caller will be applied to the SELECT statements in the UDF. When SET ROWCOUNT n applies to a SELECT statement with sub-queries, the results and ordering are always guaranteed. To avoid confusion and unexpected logical errors, it’s better to turn SET ROWCOUNT n on just before the final SELECT statement that returns the records.</p>
<p style="text-align:justify;"><strong>SQL SERVER 2005</strong><br />
In SQL server 2005, SET ROWCOUNT n has the same behavior as SQL server 2000. It’s recommended to use TOP (n) instead of SET ROWCOUNT n.
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/57/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/57/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=57&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/04/30/sql-server-set-rowcount-retrieving-or-limiting-the-first-n-records-from-a-sql-query/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Random Number Generator Script &#8211; SQL Query</title>
		<link>http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/</link>
		<comments>http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/#comments</comments>
		<pubDate>Sun, 29 Apr 2007 15:00:40 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL Random]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/29/random-number-generator-script-sql-query/</guid>
		<description><![CDATA[ Random Number Generator
There are many methods to generate random number in SQL Server.
Method 1 : Generate Random Numbers (Int) between Rang
---- Create the variables for the random number generation
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
---- This will create a random number between 1 and 999
SET @Lower = 1 ---- The lowest random number
SET @Upper [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=72&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><span style="font-weight:bold;"> Random Number Generator</span></p>
<p style="text-align:justify;">There are many methods to generate random number in SQL Server.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">Method 1 : Generate Random Numbers (Int) between Rang</span><br />
<code style="font-size:12px;"><span style="color:green;">---- Create the variables for the random number generation<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Random </span><span style="color:blue;">INT</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Upper </span><span style="color:blue;">INT</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Lower </span><span style="color:blue;">INT</span></code></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">---- This will create a random number between 1 and 999<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Lower </span><span style="color:blue;">= </span><span style="color:black;">1 </span><span style="color:green;">---- The lowest random number<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Upper </span><span style="color:blue;">= </span><span style="color:black;">999 </span><span style="color:green;">---- The highest random number<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Random </span><span style="color:blue;">= </span><span style="color:magenta;">ROUND</span><span style="color:gray;">(((</span><span style="color:#434343;">@Upper </span><span style="color:gray;">- </span><span style="color:#434343;">@Lower </span><span style="color:gray;">-</span><span style="color:black;">1</span><span style="color:gray;">) * </span><span style="color:magenta;">RAND</span><span style="color:gray;">() + </span><span style="color:#434343;">@Lower</span><span style="color:gray;">), </span><span style="color:black;">0</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Random</span></code></p>
<p><span style="font-weight:bold;">Method 2</span> : <span style="font-weight:bold;">Generate Random Float Numbers</span><br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">RAND</span><span style="color:gray;">( (</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) * </span><span style="color:black;">100000 </span><span style="color:gray;">)<br />
+ (</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">ss</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) * </span><span style="color:black;">1000 </span><span style="color:gray;">)<br />
+ </span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">ms</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) )</span></code><br />
<span style="font-weight:bold;"><br />
Method 3 : Random Numbers Quick Scripts</span><br />
<code style="font-size:12px;"><span style="color:green;">---- random float from 0 up to 20 - [0, 20)<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">20</span><span style="color:gray;">*</span><span style="color:magenta;">RAND</span><span style="color:gray;">()<br />
</span><span style="color:green;">-- random float from 10 up to 30 - [10, 30)<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">10 </span><span style="color:gray;">+ (</span><span style="color:black;">30</span><span style="color:gray;">-</span><span style="color:black;">10</span><span style="color:gray;">)*</span><span style="color:magenta;">RAND</span><span style="color:gray;">()<br />
</span><span style="color:green;">--random integer </span><span style="color:gray;">BETWEEN </span><span style="color:black;">0<br />
</span><span style="color:gray;">AND </span><span style="color:black;">20 </span><span style="color:gray;">- </span><span style="color:black;">[0, 20]<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">INT</span><span style="color:gray;">, (</span><span style="color:black;">20</span><span style="color:gray;">+</span><span style="color:black;">1</span><span style="color:gray;">)*</span><span style="color:magenta;">RAND</span><span style="color:gray;">())<br />
</span><span style="color:green;">----random integer </span><span style="color:gray;">BETWEEN </span><span style="color:black;">10<br />
</span><span style="color:gray;">AND </span><span style="color:black;">30 </span><span style="color:gray;">- </span><span style="color:black;">[10, 30]<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">10 </span><span style="color:gray;">+ </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">INT</span><span style="color:gray;">, (</span><span style="color:black;">30</span><span style="color:gray;">-</span><span style="color:black;">10</span><span style="color:gray;">+</span><span style="color:black;">1</span><span style="color:gray;">)*</span><span style="color:magenta;">RAND</span><span style="color:gray;">())</span></code><br />
<span style="font-weight:bold;"><br />
Method 4 : Random Numbers (Float, Int) Tables Based with Time</span><br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@t </span><span style="color:blue;">TABLE</span><span style="color:gray;">( </span><span style="color:black;">randnum float </span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@cnt </span><span style="color:blue;">INT</span><span style="color:gray;">; </span><span style="color:blue;">SET </span><span style="color:#434343;">@cnt </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@cnt </span><span style="color:gray;">&lt;=</span><span style="color:black;">10000<br />
</span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@cnt </span><span style="color:blue;">= </span><span style="color:#434343;">@cnt </span><span style="color:gray;">+ </span><span style="color:black;">1<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">@t<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">RAND</span><span style="color:gray;">( (</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) * </span><span style="color:black;">100000 </span><span style="color:gray;">)<br />
+ (</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">ss</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) * </span><span style="color:black;">1000 </span><span style="color:gray;">)<br />
+ </span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">ms</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) )<br />
</span><span style="color:blue;">END<br />
SELECT </span><span style="color:black;">randnum</span><span style="color:gray;">, </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*)<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">@t<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">randnum</span></code><br />
<span style="font-weight:bold;"><br />
Method 5 : Random number on a per row basis</span><br />
<code style="font-size:12px;"><span style="color:black;"> </span><span style="color:green;">---- The distribution is pretty good however there are the occasional peaks.<br />
---- If you want to change the range of values just change the 1000 to the maximum value you want.<br />
---- Use this as the source of a report server report and chart the results to see the distribution<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">randomNumber</span><span style="color:gray;">, </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">) </span><span style="color:black;">countOfRandomNumber<br />
</span><span style="color:blue;">FROM </span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">ABS</span><span style="color:gray;">(</span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">NEWID</span><span style="color:gray;">() </span><span style="color:blue;">AS </span><span style="color:black;">binary</span><span style="color:gray;">(</span><span style="color:black;">6</span><span style="color:gray;">)) %</span><span style="color:black;">1000</span><span style="color:gray;">) + </span><span style="color:black;">1 randomNumber<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sysobjects</span><span style="color:gray;">) </span><span style="color:black;">sample<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">randomNumber<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">randomNumber</span></code></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>), Simon Sabin (<a href="http://sqlblogcasts.com/blogs/simons/archive/2005/06/13/Random-number-on-a-per-row-basis.aspx" target="_blank">http://sqlblogcasts.com</a>)<br />
</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/72/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/72/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=72&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Good, Better and Best Programming Techniques</title>
		<link>http://blog.sqlauthority.com/2007/04/28/sql-server-good-better-and-best-programming-techniques/</link>
		<comments>http://blog.sqlauthority.com/2007/04/28/sql-server-good-better-and-best-programming-techniques/#comments</comments>
		<pubDate>Sat, 28 Apr 2007 14:00:12 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Backup and Restore]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/28/good-better-and-best-programming-techniques/</guid>
		<description><![CDATA[A week ago, I was invited to meeting of programmers. Subject of meeting was &#8220;Good, Better and Best Programming Techniques&#8221;. I had made small note before I went to meeting, so if I have to talk about or discuss SQL Server it can come handy. Well, I did not get chance to talk on that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=162&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">A week ago, I was invited to meeting of programmers. Subject of meeting was &#8220;Good, Better and Best Programming Techniques&#8221;. I had made small note before I went to meeting, so if I have to talk about or discuss SQL Server it can come handy. Well, I did not get chance to talk on that as it was very causal and just meeting and greetings. Everybody just talked about what they think about their job. I talked very briefly about SQL Server, my current job and some funny incident at work.</p>
<p style="text-align:justify;">Everybody laughed big when I talked about funny bug ticket I received which was about &#8211; Client does not receive Email sent by system. Well, at the end it was resolved without any programming as client did not have email address and needed to open one.</p>
<p style="text-align:justify;">Well, here is my note which I prepared to discuss in meeting. This is not complete and is not in very details. This note contains what I think is best programming technique in SQL. There are lots to add here and many opinion are very generic to SQL and other programming languages.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">Notes prepared for &#8220;Good, Better and Best Programming Techniques&#8221; meeting</span></p>
<p style="text-align:justify;">Do not prefix stored procedure with SP_ prefix. As they are first searched in master database, before it is searched in any other database.</p>
<p style="text-align:justify;">Always install latest server packs and security packs.</p>
<p style="text-align:justify;">Make sure your SQL Server runs on optimal hardware. If your operating system supports 64 bit SQL Server, install 64 bit SQL Server on it. Raid 10 Array.</p>
<p style="text-align:justify;">Reduce Network Traffic by using Stored Procedure. Return only required result set from database. If application needs paging it should have done in SQL Server instead of at application level.</p>
<p style="text-align:justify;">After running query check Actual Execution Plan for cost of the query. Query can be analyzed in Database Engine Tuning Advisor.</p>
<p style="text-align:justify;">Use User Defined Functions sparsely, use Stored Procedures instead.</p>
<p style="text-align:justify;">Stored Procedure can achieve all the tasks UDF can do. SP provides much more features than UDFs.</p>
<p style="text-align:justify;">Test system with realistic data rather than sample data. Realistic data provides better scenario for testing and reveals problems with real system before it goes to production.</p>
<p style="text-align:justify;">Do not use SELECT *, use proper column names to decrease network traffic and fewer locks on table.</p>
<p style="text-align:justify;">Avoid Cursors as it results in performance degradation. Sub Query, derived tables, CTE can perform same operation.</p>
<p style="text-align:justify;">Reduces the use of nullable columns.</p>
<p style="text-align:justify;">NULL columns consumes an extra byte on each column used as well as adds overhead in queries. Also NULL is not good for logic development for programmers.</p>
<p style="text-align:justify;">Reduce deadlocks using query hints and proper logic of order in columns.</p>
<p style="text-align:justify;">Normalized database always increases scalability and stability of the system. Do not go over 3rd normal form as it will adversely affect performance.</p>
<p style="text-align:justify;">Use WHERE clauses to compare assertive logic. Use IN rather than NOT IN even though IN will require more value to specify in clause.</p>
<p style="text-align:justify;">BLOBS must be stored filesystem and database should have path to them only. If path is common stored them in application variable and append with filename from the BLOBColumnName.</p>
<p style="text-align:justify;">Always perform referential integrity checks and data validations using constraints such as the foreign key and check constraints.</p>
<p style="text-align:justify;">SQL Server optimizer will use an index scan if the ORDER BY clause is on an indexed column.</p>
<p style="text-align:justify;">Stored Procedure should return same numbers of resultset and same columns in any input parameters. Result Set of Stored Procedure should be deterministic.</p>
<p style="text-align:justify;">Index should be created on highly selective columns, which are used in JOINS, WHERE and ORDER BY clause.</p>
<p style="text-align:justify;">Format SQL Code. Make it readable. Wrap it.</p>
<p style="text-align:justify;">Use Column name in ORDER BY clause instead of numbers.</p>
<p style="text-align:justify;">Do not use TEXT or NTEXT if possible. In SQL Server 2005 use VARCHAR(MAX) or NVARCHAR(MAX).</p>
<p style="text-align:justify;">Join tables in order that they always perform the most restrictive search first to filter out the maximum number of rows in the early phases of a multiple table join.</p>
<p style="text-align:justify;">Remember to SET NOCOUNT ON at the beginning of your SQL bataches, stored procedures, triggers to avoid network traffic. This will also reduct the chances of error on linked server.</p>
<p style="text-align:justify;">Do not use temp tables use CTE or Derived tables instead.</p>
<p style="text-align:justify;">Always take backup of all the data.</p>
<p style="text-align:justify;">Never ever work on production server.</p>
<p style="text-align:justify;">Ask someone for help if you need it. We all need to learn.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/162/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/162/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=162&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/04/28/sql-server-good-better-and-best-programming-techniques/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server Interview Questions and Answers &#8211; Part 6</title>
		<link>http://blog.sqlauthority.com/2007/04/20/sql-server-interview-questions-part-6/</link>
		<comments>http://blog.sqlauthority.com/2007/04/20/sql-server-interview-questions-part-6/#comments</comments>
		<pubDate>Fri, 20 Apr 2007 15:00:17 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Backup and Restore]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/20/sql-server-interview-questions-part-6/</guid>
		<description><![CDATA[UPDATE : Interview Questions and Answers are now updated with SQL Server 2008 Questions and its answers. New Location : SQL Server 2008 Interview Questions and Answers.
What are the properties of the Relational tables?
Relational tables have six properties:

 Values are atomic.
 Column values are of the same kind.
 Each row is unique.
 The sequence of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=64&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h4 style="text-align:justify;"><span style="color:#ff0000;"><strong>UPDATE </strong>: Interview Questions and Answers are now updated with SQL Server 2008 Questions and its answers. <strong>New Location : <a href="http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/" target="_blank">SQL Server 2008 Interview Questions and Answers.</a></strong></span></h4>
<p style="text-align:justify;"><span style="font-weight:bold;">What are the properties of the Relational tables?</span><br />
Relational tables have six properties:</p>
<ul style="text-align:justify;">
<li> Values are atomic.</li>
<li> Column values are of the same kind.</li>
<li> Each row is unique.</li>
<li> The sequence of columns is insignificant.</li>
<li> The sequence of rows is insignificant.</li>
<li> Each column must have a unique name.</li>
</ul>
<p style="text-align:justify;"><span style="font-weight:bold;"> What is De-normalization?</span><br />
De-normalization is the process of attempting to optimize the performance of a database by adding redundant data. It is sometimes necessary because current DBMSs implement the relational model poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while providing physical storage of data that is tuned for high performance. De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access.</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> How to get @@error and @@rowcount at the same time?<br />
</span>If @@Rowcount is checked after Error checking statement then it will have 0 as the value of @@Recordcount as it would have been reset.<br />
And if @@Recordcount is checked before the error-checking statement then @@Error would get reset. To get @@error and @@rowcount at the same time do both in same statement and store them in local variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What is Identity?</span><br />
Identity (or AutoNumber) is a column that automatically generates numeric values. A start and increment value can be set, but most DBA leave these at 1. A GUID column also generates numbers, the value of this cannot be controled. Identity/GUID columns do not need to be indexed.</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> What is a Scheduled Jobs or What is a Scheduled Tasks? </span><br />
Scheduled tasks let user automate processes that run on regular or predictable cycles. User can schedule administrative tasks, such as cube processing, to run during times of slow business activity. User can also determine the order in which tasks run by creating job steps within a SQL Server Agent job. E.g. Back up database, Update Stats of Tables. Job steps give user control over flow of execution.  If one job fails, user can configure SQL Server Agent to continue to run the remaining tasks or to stop execution.</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> What is a table called, if it does not have neither Cluster nor Non-cluster Index? What is it used for?<br />
</span>Unindexed table or <span style="font-weight:bold;font-style:italic;">Heap</span>. Microsoft Press Books and Book On Line (BOL) refers it as Heap.<br />
A heap is a table that does not have a clustered index and, therefore, the pages are not linked by pointers. The IAM pages are the only structures that link the pages in a table together.<br />
Unindexed tables are good for fast storing of data. Many times it is better to drop all indexes from table and than do bulk of inserts and to restore those indexes after that.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What is BCP? When does it used? </span><br />
BulkCopy is a tool used to copy huge amount of data from tables and views. BCP does not copy the structures same as source to destination.</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> How do you load large data to the SQL server database?<br />
</span>BulkCopy is a tool used to copy huge amount of data from tables. BULK INSERT command helps to Imports a data file into a database table or view in a user-specified format.</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> Can we rewrite subqueries into simple select statements or with joins? </span><br />
Subqueries can often be re-written to use a standard      outer join, resulting in faster performance.  As we may know, an outer join      uses the plus sign (+) operator to tell the database to return all      non-matching rows with NULL values.  Hence we combine the outer join with a      NULL test in the WHERE clause to reproduce the result set without using a      sub-query.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">Can SQL Servers linked to other servers like Oracle?</span><br />
SQL Server can be lined to any server provided it has OLE-DB provider from Microsoft to allow a link. E.g. Oracle has a OLE-DB provider for oracle that Microsoft provides to add it as linked server to SQL Server group.</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> How to know which index a table is using? </span><br />
SELECT table_name,index_name FROM user_constraints</p>
<p style="text-align:justify;"><span style="font-weight:bold;">How to copy the tables, schema and views from one SQL server to another?</span><br />
Microsoft SQL Server 2000 Data Transformation Services (DTS) is a set of graphical tools and programmable objects that lets user extract, transform, and consolidate data from disparate sources into single or multiple destinations.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What is Self Join?</span><br />
This is a particular case when one table joins to itself, with one or two aliases to avoid confusion. A self join can be of any type, as long as the joined tables are the same. A self join is rather unique in that it involves a relationship with only one table. The common example is when company have a hierarchal reporting structure whereby one member of staff reports to another.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What is Cross Join?</span><br />
A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table. The common example is when company wants to combine each product with a pricing table to analyze each product at each price.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">Which virtual table does a trigger use?</span><br />
Inserted and Deleted.
</p>
<p style="text-align:justify;"><span style="font-weight:bold;">List few advantages of Stored Procedure.</span></p>
<ul style="text-align:justify;">
<li>Stored procedure can reduced network traffic and latency, boosting application performance.</li>
<li>Stored procedure execution plans can be reused, staying cached in SQL Server&#8217;s memory, reducing server overhead.</li>
<li>Stored procedures help promote code reuse.</li>
<li>Stored procedures can encapsulate logic. You can change stored procedure code without affecting clients.</li>
<li>Stored procedures provide better security to your data.</li>
</ul>
<p style="text-align:justify;"><span style="font-weight:bold;">What is DataWarehousing?</span></p>
<ul style="text-align:justify;">
<li><strong>Subject-oriented</strong>, meaning that the data in the database is organized so that all the data elements relating to the same real-world event or object are linked together;</li>
<li><strong>Time-variant</strong>, meaning that the changes to the data in the database are tracked and recorded so that reports can be produced showing changes over time;</li>
<li><strong>Non-volatile</strong>, meaning that data in the database is never over-written or deleted, once committed, the data is static, read-only, but retained for future reporting;</li>
<li><strong>Integrated</strong>, meaning that the database contains data from most or all of an organization&#8217;s operational applications, and that this data is made consistent.</li>
</ul>
<p style="text-align:justify;"><span style="font-weight:bold;">What is OLTP(OnLine Transaction Processing)?</span><br />
In OLTP &#8211; online transaction processing systems relational database design use the discipline of data modeling and generally follow the Codd rules of data normalization in order to ensure absolute data integrity. Using these rules complex information is broken down into its most simple structures (a table) where all of the individual atomic level elements relate to each other and satisfy the normalization rules.</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> How do SQL server 2000 and XML linked? Can XML be used to access data?</span><br />
<span style="font-style:italic;font-weight:bold;">FOR XML (ROW, AUTO, EXPLICIT)</span><br />
You can execute SQL queries against existing relational databases to return results as XML rather than standard rowsets. These queries can be executed directly or from within stored procedures. To retrieve XML results, use the FOR XML clause of the SELECT statement and specify an XML mode of RAW, AUTO, or EXPLICIT.</p>
<p style="text-align:justify;"><span style="font-weight:bold;font-style:italic;">OPENXML</span><br />
OPENXML is a Transact-SQL keyword that provides a relational/rowset view over an in-memory XML document. OPENXML is a rowset provider similar to a table or a view. OPENXML provides a way to access XML data within the Transact-SQL context by transferring data from an XML document into the relational tables. Thus, OPENXML allows you to manage an XML document and its interaction with the relational environment.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What is an execution plan? When would you use it? How would you view the execution plan?</span><br />
An execution plan is basically a road map that graphically or textually shows the data retrieval methods chosen by the SQL Server query optimizer for a stored procedure or ad-hoc query and is a very useful tool for a developer to understand the performance characteristics of a query or stored procedure since the plan is the one that SQL Server will place in its cache and use to execute the stored procedure or query. From within Query Analyzer is an option called &#8220;Show Execution Plan&#8221; (located on the Query drop-down menu). If this option is turned on it will display query execution plan in separate window when query is ran again.</p>
<p style="text-align:justify;"><strong>Complete Series of SQL Server Interview Questions and Answers</strong><br />
<a href="http://blog.sqlauthority.com/2007/04/15/sql-server-interview-questions-and-answers-introduction/">SQL Server Interview Questions and Answers &#8211; Introduction</a><br />
<a href="http://blog.sqlauthority.com/2007/04/15/sql-server-interview-questions/">SQL Server Interview Questions and Answers &#8211; Part 1</a><br />
<a href="http://blog.sqlauthority.com/2007/04/16/sql-server-interview-questions-part-2/">SQL Server Interview Questions and Answers &#8211; Part 2</a><br />
<a href="http://blog.sqlauthority.com/2007/04/17/sql-server-interview-questions-part-3/">SQL Server Interview Questions and Answers &#8211; Part 3</a><br />
<a href="http://blog.sqlauthority.com/2007/04/18/sql-server-interview-questions-part-4/">SQL Server Interview Questions and Answers &#8211; Part 4</a><br />
<a href="http://blog.sqlauthority.com/2007/04/19/sql-server-interview-questions-part-5/">SQL Server Interview Questions and Answers &#8211; Part 5</a><br />
<a href="http://blog.sqlauthority.com/2007/04/20/sql-server-interview-questions-part-6/">SQL Server Interview Questions and Answers &#8211; Part 6</a><br />
<a href="http://blog.sqlauthority.com/2007/04/21/sql-server-interview-questions-and-answers-complete-list-download/"><strong>SQL Server Interview Questions and Answers Complete List Download</strong></a></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/64/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/64/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=64&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/04/20/sql-server-interview-questions-part-6/feed/</wfw:commentRss>
		<slash:comments>83</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server Interview Questions and Answers &#8211; Part 5</title>
		<link>http://blog.sqlauthority.com/2007/04/19/sql-server-interview-questions-part-5/</link>
		<comments>http://blog.sqlauthority.com/2007/04/19/sql-server-interview-questions-part-5/#comments</comments>
		<pubDate>Thu, 19 Apr 2007 15:00:06 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/19/sql-server-interview-questions-part-5/</guid>
		<description><![CDATA[UPDATE : Interview Questions and Answers are now updated with SQL Server 2008 Questions and its answers. New Location : SQL Server 2008 Interview Questions and Answers.
 What command do we use to rename a db? 
sp_renamedb ‘oldname’ , ‘newname’
If someone is using db it will not accept sp_renmaedb. In that case first bring db [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=62&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h4 style="text-align:justify;"><span style="color:#ff0000;"><strong>UPDATE </strong>: Interview Questions and Answers are now updated with SQL Server 2008 Questions and its answers. <strong>New Location : <a href="http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/" target="_blank">SQL Server 2008 Interview Questions and Answers.</a></strong></span></h4>
<p style="text-align:justify;"><span style="font-weight:bold;"> What command do we use to rename a db? </span><br />
sp_renamedb ‘oldname’ , ‘newname’<br />
If someone is using db it will not accept sp_renmaedb. In that case first bring db to single user using sp_dboptions. Use sp_renamedb to rename database. Use sp_dboptions to bring database to multi user mode.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What is sp_configure commands and set commands?</span><br />
Use sp_configure to display or change server-level settings. To change database-level settings, use ALTER DATABASE. To change settings that affect only the current user session, use the SET statement.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What are the different types of replication? Explain.</span><br />
The SQL Server 2000-supported replication types are as follows:</p>
<ul style="text-align:justify;">
<li> Transactional</li>
<li> Snapshot</li>
<li> Merge</li>
</ul>
<p style="text-align:justify;"><strong><span style="font-style:italic;">Snapshot replication</span></strong> distributes data exactly as it appears at a specific moment in time and does not monitor for updates to the data. Snapshot replication is best used as a method for replicating data that changes infrequently or where the most up-to-date values (low latency) are not a requirement. When synchronization occurs, the entire snapshot is generated and sent to Subscribers.</p>
<p style="text-align:justify;"><strong><span style="font-style:italic;">Transactional replication</span></strong>, an initial snapshot of data is applied at Subscribers, and then when data modifications are made at the Publisher, the individual transactions are captured and propagated to Subscribers.</p>
<p style="text-align:justify;"><strong><span style="font-style:italic;">Merge replication</span></strong> is the process of distributing data from Publisher to Subscribers, allowing the Publisher and Subscribers to make updates while connected or disconnected, and then merging the updates between sites when they are connected.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What are the OS services that the SQL Server installation adds?</span><br />
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What are three SQL keywords used to change or set someone’s permissions?<br />
</span>GRANT, DENY, and REVOKE.</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> What does it mean to have quoted_identifier on? What are the implications of having it off?</span><br />
When SET QUOTED_IDENTIFIER is ON, identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers.</p>
<p><span style="font-weight:bold;">What is the STUFF function and how does it differ from the REPLACE function? </span><br />
<strong>STUFF</strong> function to overwrite existing characters. Using this syntax, STUFF(string_expression, start, length, replacement_characters), string_expression is the string that will have characters substituted, start is the starting position, length is the number of characters in the string that are substituted, and replacement_characters are the new characters interjected into the string.<br />
<strong>REPLACE</strong> function to replace existing characters of all occurance. Using this syntax REPLACE(string_expression, search_string, replacement_string), where every incidence of search_string found in the string_expression will be replaced with replacement_string.
</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> Using query analyzer, name 3 ways to get an accurate count of the number of records in a table?</span><br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">table1<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*)<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">table1<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">rows<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sysindexes<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">id </span><span style="color:blue;">= </span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">(</span><span style="color:black;">table1</span><span style="color:gray;">)<br />
AND </span><span style="color:black;">indid </span><span style="color:gray;">&lt; </span><span style="color:black;">2</span></code><br />
<span style="font-weight:bold;">How to rebuild Master Database?</span><br />
Shutdown Microsoft SQL Server 2000, and then run Rebuildm.exe. This is located in the Program Files\Microsoft SQL Server\80\Tools\Binn directory.<br />
In the Rebuild Master dialog box, click Browse.<br />
In the Browse for Folder dialog box, select the \Data folder on the SQL Server 2000 compact disc or in the shared network directory from which SQL Server 2000 was installed, and then click OK.<br />
Click Settings. In the Collation Settings dialog box, verify or change settings used for the master database and all other databases.<br />
Initially, the default collation settings are shown, but these may not match the collation selected during setup. You can select the same settings used during setup or select new collation settings. When done, click OK.<br />
In the Rebuild Master dialog box, click Rebuild to start the process.<br />
The Rebuild Master utility reinstalls the master database.<br />
To continue, you may need to stop a server that is running.<br />
Source: http://msdn2.microsoft.com/en-us/library/aa197950(SQL.80).aspx</p>
<p style="text-align:justify;"><span style="font-weight:bold;"> What is the basic functions for master, msdb, model, tempdb databases?</span><br />
The <span style="font-weight:bold;font-style:italic;">Master</span> database holds information for all databases located on the SQL Server instance and is the glue that holds the engine together. Because SQL Server cannot start without a functioning master database, you must administer this database with care.<br />
The <span style="font-weight:bold;font-style:italic;">msdb </span>database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server jobs, and some replication information such as for log shipping.<br />
The <span style="font-weight:bold;font-style:italic;">tempdb</span> holds temporary objects such as global and local temporary tables and stored procedures.<br />
The <span style="font-weight:bold;font-style:italic;">model</span> is essentially a template database used in the creation of any new user database created in the instance.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">What are primary keys and foreign keys? </span><br />
<span style="font-style:italic;font-weight:bold;">Primary keys</span> are the unique identifiers for each row. They must contain unique values and cannot be null. Due to their importance in relational databases, Primary keys are the most fundamental of all keys and constraints. A table can have only one Primary key.<br />
<span style="font-weight:bold;font-style:italic;">Foreign keys</span> are both a method of ensuring data integrity and a manifestation of the relationship between tables.</p>
<p style="text-align:justify;"><strong> What is data integrity? Explain constraints?</strong><br />
<span class="DropCap">D</span>ata integrity is an important feature in SQL Server. When used properly, it ensures that data is accurate, correct, and valid. It also acts as a trap for otherwise undetectable bugs within applications.</p>
<p>A <strong>PRIMARY KEY</strong> constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row and only one primary key constraint can be created for each table. The primary key constraints are used to enforce entity integrity.
</p>
<p style="text-align:justify;">A <strong>UNIQUE</strong> constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints.</p>
<p style="text-align:justify;">A <strong>FOREIGN KEY</strong> constraint prevents any actions that would destroy links between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity.</p>
<p style="text-align:justify;">A <strong>CHECK</strong> constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity.</p>
<p style="text-align:justify;">A <strong>NOT NULL</strong> constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.</p>
<p style="text-align:justify;"><strong>Complete Series of SQL Server Interview Questions and Answers</strong><br />
<a href="http://blog.sqlauthority.com/2007/04/15/sql-server-interview-questions-and-answers-introduction/">SQL Server Interview Questions and Answers &#8211; Introduction</a><br />
<a href="http://blog.sqlauthority.com/2007/04/15/sql-server-interview-questions/">SQL Server Interview Questions and Answers &#8211; Part 1</a><br />
<a href="http://blog.sqlauthority.com/2007/04/16/sql-server-interview-questions-part-2/">SQL Server Interview Questions and Answers &#8211; Part 2</a><br />
<a href="http://blog.sqlauthority.com/2007/04/17/sql-server-interview-questions-part-3/">SQL Server Interview Questions and Answers &#8211; Part 3</a><br />
<a href="http://blog.sqlauthority.com/2007/04/18/sql-server-interview-questions-part-4/">SQL Server Interview Questions and Answers &#8211; Part 4</a><br />
<a href="http://blog.sqlauthority.com/2007/04/19/sql-server-interview-questions-part-5/">SQL Server Interview Questions and Answers &#8211; Part 5</a><br />
<a href="http://blog.sqlauthority.com/2007/04/20/sql-server-interview-questions-part-6/">SQL Server Interview Questions and Answers &#8211; Part 6</a><br />
<a href="http://blog.sqlauthority.com/2007/04/21/sql-server-interview-questions-and-answers-complete-list-download/"><strong>SQL Server Interview Questions and Answers Complete List Download</strong></a></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/62/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/62/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=62&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/04/19/sql-server-interview-questions-part-5/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
	</channel>
</rss>