<?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; Readers Contribution</title>
	<atom:link href="http://blog.sqlauthority.com/category/readers-contribution/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; Readers Contribution</title>
		<link>http://blog.sqlauthority.com</link>
	</image>
			<item>
		<title>SQL SERVER &#8211; Change Collation of Database Column &#8211; T-SQL Script &#8211; Consolidating Collations &#8211; Extention Script</title>
		<link>http://blog.sqlauthority.com/2009/10/19/sql-server-change-collation-of-database-column-t-sql-script-consolidating-collations-extention-script/</link>
		<comments>http://blog.sqlauthority.com/2009/10/19/sql-server-change-collation-of-database-column-t-sql-script-consolidating-collations-extention-script/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 01:30:55 +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 Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></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 Collation]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7139</guid>
		<description><![CDATA[This document is created by Brian Cidern, he has written this excellent extension to  SQL Expert who SQL SERVER – Change Collation of Database Column – T-SQL Script. His scripts are not only extremely helpful to achieve the task of consolidating collations in quick script. His script not only works perfectly but excellent piece [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7139&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This document is created by <span style="color:#000080;"><strong>Brian Cidern</strong></span>, he has written this excellent extension to  SQL Expert who SQL SERVER – Change Collation of Database Column – T-SQL Script. His scripts are not only extremely helpful to achieve the task of <em><strong>consolidating collations</strong></em> in quick script. His script not only works perfectly but excellent piece of code and logic.</p>
<p style="text-align:justify;">Hats off to you <strong>Brian</strong>! You can reach Brian at his email address (brians.sql.blog (at) gmail (dot) com) or leave comment here.</p>
<h3 style="text-align:justify;"><strong><a href="http://www.pinaldave.com/best-sql-server-download.cfm?Download=SQL_Collation_Consolidation_Scripts" target="_blank">Download all scripts and explanation here</a></strong></h3>
<p style="text-align:justify;"><strong>About Collation Consolidation</strong></p>
<p style="text-align:justify;">At some time in your DBA career, you may find yourself in a position when you sit back and realize that your database collations have somehow run amuck, or are faced with the ever annoying CANNOT RESOLVE COLLATION message when trying to join data of varying collation settings.  I’m sure there are as many reasons as to how you’ve come to this juncture as there are readers.  Maybe you have DBA’s and instances around the world and the local staff are using their own collations.  Or, maybe you’ve learned the hard way that ALTER DATABASE x SET COLLATION y doesn’t traverse.  Whatever it is, you’re probably here for the one underlying reason.  Manually consolidating collations would be a nightmare.  So, without loading to much fluff, let’s jump right in.</p>
<p style="text-align:justify;">Here is the basic approach:</p>
<ol style="text-align:justify;">
<li>Identify all the      columns which have incorrect collation values.</li>
<li>Identify all      objects bound to above columns, including indexes, keys, checks and UDF’s,</li>
<li>Script out all      of the above object DDL.</li>
<li>Drop all of the      objects.</li>
<li>Update all the      columns with the correct collation</li>
<li>Recreate all of      the dropped objects using the DDL generated in step 3</li>
</ol>
<p style="text-align:justify;">This is done with a collection of non-destructive scripts which generate the DDL to perform all of the above.  This generated DDL MUST be saved to scripts for later use on the target databases.  And obviously, you’ll need one set of scripts per database.  If that requires clarification, just stop reading now.</p>
<p style="text-align:justify;">In this article, I give to you the four scripts to do all this and will try to provide as much understanding as possible.  The first script is purely to create a stored procedure which will be repeatedly called.  This proc will need to exist in a database named “DBADB”.  If you want to use a different database, you’ll need to do a search and replace in the first script and the last script since the database name is hard-coded.  I tried to make these somewhat generic, but the only approach that came to mind would be to use OLE to invoke the VBScript engine to prompt you for the name of the database where this stored procedure is located.  Overkill in my opinion.  Ctrl-H is your friend here.</p>
<p style="text-align:justify;">The script to perform step 3 above uses DMO via OLE, so if you’ve disabled the extended stored procedures; sp_OACreate, sp_OASetProperty, sp_OAMethod, etc, you won’t be able to continue until they’ve been enabled.</p>
<p style="text-align:justify;">One final note.  If you’re not a member of the System Administrators role, please don’t try to execute these.  You’ll probably find your account revoked quickly.</p>
<p style="text-align:justify;">Ok, time to roll up your sleeves.</p>
<p style="text-align:justify;"><strong>Script 1 – The DDL Generator</strong></p>
<p style="text-align:justify;">This first script is to create a stored procedure.  This procedure must reside in a location that will not interfere with other databases, whether they’re development, test or production.  The SP uses DMO via OLE to capture a buffer dump of the object code.  The result is the same as if you right-clicked an object and selected “Script to new window as…”</p>
<p style="text-align:justify;">The DMO hierarchy of a SQL instance is weird.  Object reference isn’t particularly intuitive.  But, for the most part, objects are contained within the associated table collection.  In DBA language, that would look like</p>
<p style="text-align:justify;">Table 1:M Checks</p>
<p style="text-align:justify;">Table 1:M Keys</p>
<p style="text-align:justify;">Table 1:M Indexes</p>
<p style="text-align:justify;">Database 1:M UserDefinedFunctions</p>
<p style="text-align:justify;">Therefore, to locate a particular object in the DMO hierarchy, you would need to pass in all the required parameters, including the object type.  So, for checks, keys and indexes, you must also pass in the database name and the parent table name.  For functions, only the database name.</p>
<p style="text-align:justify;">sp_scriptObject(</p>
<p style="text-align:justify;">@in_dbName SysName,</p>
<p style="text-align:justify;">@in_objType VarChar(100),</p>
<p style="text-align:justify;">@in_objName VarChar(100),</p>
<p style="text-align:justify;">@in_objSubName VarChar(100) = NULL</p>
<p style="text-align:justify;">)</p>
<p style="text-align:justify;">Now, the good news.  The subsequent scripts will do all of the above automatically, and this script will be called repeatedly.</p>
<p style="text-align:justify;"><strong>Implementing this script.</strong></p>
<p style="text-align:justify;">As I mentioned, this script will be called repeatedly.  The script from whence it’s called will need to be modified to make reference to the correct database name.  These scripts have been designed to work with a DBA-use only database called “DBADB”.  Therefore, if you choose to keep this procedure located in a database of a different name, you’ll need to perform a search and replace for all the “DBADB” reference.  Otherwise, you will need to create a database named “DBADB”.</p>
<p style="text-align:justify;">Execute the first script.  This will create the necessary stored procedure.</p>
<p style="text-align:justify;"><strong>Script 2 – Drop Dependencies</strong></p>
<p style="text-align:justify;">The name for this script is somewhat deceiving.  It is a non-destructive script and only performs a set of SELECT statements.  Rather, this script generates a collection of DROP [object] statements.</p>
<p style="text-align:justify;">The goal here is to identify all the objects that are bound to columns which have incorrect collation settings.  There is no clean way to pull them all back in a single statement since determining this is handled differently for the various types of objects.  So, they’re all concatenated together with UNION’s.  The orders in which these are executed are as follows:</p>
<ol style="text-align:justify;">
<li>Table Functions</li>
<li>Unique      Constraints</li>
<li>Check      Constraints</li>
<li>Indexes</li>
</ol>
<p style="text-align:justify;"><em>You must also edit this script to use your desired collation.  Perform a search and replace of SQL_Latin1_General_CI_AS to your chosen collation.</em></p>
<p style="text-align:justify;">It’s performed in this order in attempt to avoid dependency issues.</p>
<p style="text-align:justify;">The result is a collection of DROP statements.  This must then be copy and pasted into a script and saved for later use.  Best to use a naming convention that reflects the name of the database, and that this will be the first script to execute when you’re ready to begin the patching, for example: myDatabase_post-script_1.sql, myDatabase_post-script_2.sql, etc.</p>
<p style="text-align:justify;">You should take note, it is possible that some databases may not have any objects that are bound to columns that need to be updated, so it’s perfectly fine if this script produces no results.</p>
<p style="text-align:justify;"><strong>Script 3 – Change Collations</strong></p>
<p style="text-align:justify;">Much like script 2, this script is also non-destructive and will produce a collection of DDL statements to update the column collations.</p>
<p style="text-align:justify;"><em>You must also edit this script to use your desired collation.  Perform a search and replace of SQL_Latin1_General_CI_AS to your chosen collation.</em></p>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;"> </span></strong></p>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">VERY IMPORTANT</span></strong>.  These scripts were originally intended to allow us to consolidate all our collations in a SQL 2000 to SQL 2008 migration.  Therefore, this script WILL produce two lines of code that you may or may not want.</p>
<p style="text-align:justify;">ALTER DATABASE &#8216; + DB_NAME() + &#8216; SET COMPATIBILITY_LEVEL=100</p>
<p style="text-align:justify;">and</p>
<p style="text-align:justify;">ALTER DATABASE &#8216; + DB_NAME() + &#8216; COLLATE &#8216; + @collation</p>
<p style="text-align:justify;">where @collation is a variable defined at the beginning of the script.</p>
<p style="text-align:justify;">You can alter the original script I’ve provided, or you can simply remove them from the output before saving.</p>
<p style="text-align:justify;">The remaining results will be a collection of statements to alter the column collations:</p>
<p style="text-align:justify;">ALTER TABLE [tbl] ALTER COLUMN [clm] column_spec() COLLATE [new_collation]</p>
<p style="text-align:justify;">Once this has been executed, copy and paste the output into another script file for later use (myDatabase_post-script_2.sql)</p>
<p style="text-align:justify;"><strong>Script 4 – Create Dependent Objects</strong></p>
<p style="text-align:justify;">This is where most of the work takes place.</p>
<p style="text-align:justify;"><em>You must also edit this script to use your desired collation.  Perform a search and replace of SQL_Latin1_General_CI_AS to your chosen collation.</em></p>
<p style="text-align:justify;">Open the script, connect to the desired database and hit the [fire] button.  Again, like those previous, this script is non-destructive, and produces a series of DDL statements.</p>
<p style="text-align:justify;">The first you’ll notice in the output is the “USE DBADB” statement.  It is very important to note here that if the stored procedure (sp_scriptObject) from the very first script is stored in another database, that this is reflected in the output.</p>
<p style="text-align:justify;">The remainder of the output looks like:</p>
<p style="text-align:justify;">EXEC DBADB.dbo.sp_scriptObject…</p>
<p style="text-align:justify;">With all of the required parameters, based on the type and location of the object.  The other thing you may notice here is that the order in which these statements are in, is the exact reverse of the order from the 2<sup>nd</sup> script; again, with the intent to avoid dependency crashes.</p>
<p style="text-align:justify;">This output now needs to be copy and pasted to a new query window – not to a file.  The output of the new window should be set to text (Query &gt; Results in Text) or (Ctrl-T).  Execute the statements.  Be aware, that this could take a significant amount of time based on the number of objects and how complex they are.</p>
<p style="text-align:justify;">But, in essence, you will be trapping a buffer dump for each object that needs to be dropped.</p>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">VERY IMPORTANT.</span></strong></p>
<p style="text-align:justify;">There may be a case where an object’s DDL is simply too large.  There are limitations in which the VBScript engine stores string data.  I can’t recall exactly what the issue was, nor do I care to look it up again. But basically, the buffer is limited to 8k.  If your object DDL is greater than 8k, an error will be thrown and the object DDL will NOT be trapped.</p>
<p style="text-align:justify;">After this script has finished, you must first scan the output for errors.  If any are found, identify the object which was not scripted and manually script those and paste them into the output.</p>
<p style="text-align:justify;">This output must then be saved to a final script for execution against the target database.</p>
<p style="text-align:justify;"><strong>Final Step</strong></p>
<p style="text-align:justify;">In the end, the above work will have produced 3 scripts that now need to be run against the target database.  Now is a good time to clarify that these generated scripts are very destructive.  So, please take your time, test, test and test.  If you choose to do this on a production box, your career could be at stake.  There is never one-size-fits-all solution, so for each scenario, these scripts may required modifications.  These were produced to fix my needs, but I did try to keep them as generic as possible for re-use.</p>
<p style="text-align:justify;">On your target database, execute each of the generated scripts, obviously in the order specified.</p>
<p style="text-align:justify;">The net result will leave your database with each column, along with the database set at your desired collation setting.</p>
<p style="text-align:justify;"><strong>The Quick and Dirty Approach</strong></p>
<p style="text-align:justify;">This section is for those who don’t really care to know the details and simply provides an exact step-by-step.</p>
<ol style="text-align:justify;">
<li>Backup the      target database.</li>
<li>Copy the 4      scripts to an empty folder.</li>
<li>Open      Pre-Script_1_DROP_DEPENDENCIES.sql in a text editor and perform a search      and replace of “Latin1_General_CI_AS” and change this to the desired      collation.</li>
<li>Open Pre-Script_2_CHANGE_COLLATIONS.sql      in a text editor and perform a search and replace of “Latin1_General_CI_AS”      and change this to the desired collation.</li>
<li>Open Pre-Script_3_CREATE_DEPENDENCIES.sql      in a text editor and perform a search and replace of “Latin1_General_CI_AS”      and change this to the desired collation.</li>
<li>Create a      database named “DBADB”</li>
<li>Execute Pre-Script_0_DBADB.sp_scriptObject.sql</li>
<li>Change the      working database to the one which requires collation changes.</li>
<li>Execute Pre-Script_1_DROP_DEPENDENCIES.sql</li>
<li>Save the output      to a text file named “dbName_post-script_1.sql”</li>
<li>Execute Pre-Script_2_CHANGE_COLLATIONS.sql</li>
<li>Save the output      to a text file named “dbName_post-script_2.sql”</li>
<li>Execute Pre-Script_3_CREATE_DEPENDENCIES.sql</li>
<li>Copy the output      to a new query window and execute.</li>
<li>Scan the      secondary output for errors.       Identify any failed objects and manually script out the DDL.  Paste it into the location where the      error occurred.</li>
<li>Now, save this      output to a text file named “dbName_post-script_3.sql”</li>
<li>Copy      dbName_post-script_1.sql, dbName_post-script_2.sql, and dbName_post-script_3.sql      to the target machine.</li>
<li>Connect to the      desired target database and execute each of the above post-scripts in      numeric order.</li>
</ol>
<p style="text-align:justify;">Good luck.  Please heed any warnings I may have mentioned.  If you have any questions, certainly send me an email and I will try to answer promptly.  But, also please be patient, I do have a full time job that takes priority.</p>
<p style="text-align:justify;"><strong>Brian Cidern<br />
brians.sql.blog (at) gmail (dot) com</strong></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 Readers Contribution, Readers Question, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQL Utility, T SQL, Technology Tagged: SQL Collation <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7139&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/19/sql-server-change-collation-of-database-column-t-sql-script-consolidating-collations-extention-script/feed/</wfw:commentRss>
		<slash:comments>0</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; Interesting Observation &#8211; Execution Plan and Results of Aggregate Concatenation Queries</title>
		<link>http://blog.sqlauthority.com/2009/09/29/sql-server-interesting-observation-execution-plan-and-results-of-aggregate-concatenation-queries/</link>
		<comments>http://blog.sqlauthority.com/2009/09/29/sql-server-interesting-observation-execution-plan-and-results-of-aggregate-concatenation-queries/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 01:30:32 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL View]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6930</guid>
		<description><![CDATA[Working with SQL Server has never seems to be monotonous – no matter how long one has worked with it. Quite often, I come across some excellent comments that I feel like acknowledging them as blog posts. Recently, I wrote an article on SQL SERVER – Execution Plan and Results of Aggregate Concatenation Queries Depend [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6930&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Working with SQL Server has never seems to be monotonous – no matter how long one has worked with it. Quite often, I come across some excellent comments that I feel like acknowledging them as blog posts. Recently, I wrote an article on <a href="http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/" target="_blank"><strong>SQL SERVER – Execution Plan and Results of Aggregate Concatenation Queries Depend Upon Expression Location</strong></a>, which is well received in community.</p>
<p style="text-align:justify;">Before you read this article further, I request you to read <a href="http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/" target="_blank">original article</a>. I received very interesting comments from Bob on the blog, where he explained why this is happening. Further, he talked about a similar kind of example. Let us first read his comment, and then we will execute his example and see the resultset.</p>
<p style="text-align:justify;">Comment from <strong><a href="http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/#comment-56103" target="_blank">Bob</a></strong></p>
<p style="padding-left:30px;text-align:justify;">pinaldave,</p>
<p style="padding-left:30px;text-align:justify;">If you want to see what’s going on here, I think you need to shift your point of view from an implementation-centric view to an ANSI point of view. ANSI does not guarantee processing order. Figure 2 is interesting, but it will be potentially misleading if you don’t understand the ANSI rule-set SQL Server operates under in most cases. Implementation thinking can certainly be useful at times when you really need that multi-million row query to finish before the backups fire off, but in this case, it’s counterproductive to understanding what is going on.</p>
<p style="padding-left:30px;text-align:justify;">First off, your statements all return a single row, which were properly sorted according to your ORDER BY expression; which is to say that there was really no sorting to be done because only a single row is returned. So let’s forget about the ORDER BY. Forget that the execution plan shows 2 rows being sorted — that’s implementation specific. A different vendor’s product could have an optimizer smart enough to see that only a single row can ever be returned from this query and therefore, avoid the unnecessary sort altogether.</p>
<p style="padding-left:30px;text-align:justify;">Secondly, you are not guaranteed that the string concatenation will occur in any particular order. The ORDER BY clause only pertains to the final results from an ANSI perspective (at least, for these queries). MS SQL Server is right in line with ANSI and will not guarantee you anything different. Don’t expect to get AB in every case.</p>
<p style="padding-left:30px;text-align:justify;">Finally, SQL works using relational sets, so the construct varchar = varchar + varchar forms a relational set that is evaluated accordingly. I have seen this type of construct used many times and it works sometimes – until it doesn’t. This is why you get only B in one example where I suspect you wanted AB. After thinking about it a bit, I built this example which I hope is just different enough to show you the same mechanism is at work here:<br />
DECLARE @sum INT<br />
SELECT @sum = 0<br />
SELECT @sum = @sum + num FROM (<br />
SELECT 1 [num] UNION SELECT 2 [num]<br />
) [a] ORDER BY (num * num)<br />
SELECT @sum [Is it 3]</p>
<p style="padding-left:30px;text-align:justify;">I tried to show two things here. The first is that the ORDER BY isn’t doing what you think it’s doing with respect to the order of concatenation in your query. The order here is nonsensical. The second thing I think the example shows is that 1+2 doesn’t equal 3 with this @ = @ + col construct in all cases. It’s a bad construct to use. Remove the ORDER BY and you get 3, leave it in and you get 2. Heck, someone else could get 1 in theory. There’s a case I see all the time where this is used, but I can’t quite recall it. I’ll post it if I think of it again.</p>
<p style="text-align:justify;">I must admit that he has made excellent point and explained the concept very well as well. Just for clarity, we will see the implementation of the example mentioned by him to understand how it works.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@sum </span><span style="color:blue;">INT<br />
SELECT </span><span style="color:#434343;">@sum </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sum </span><span style="color:blue;">= </span><span style="color:#434343;">@sum </span><span style="color:gray;">+ </span><span style="color:black;">num </span><span style="color:blue;">FROM </span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">1 [num] </span><span style="color:blue;">UNION SELECT </span><span style="color:black;">2 [num]<br />
</span><span style="color:gray;">) </span><span style="color:black;">[a] </span><span style="color:blue;">ORDER BY </span><span style="color:gray;">(</span><span style="color:black;">num </span><span style="color:gray;">* </span><span style="color:black;">num</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sum </span><span style="color:black;">WithOrderBy<br />
GO<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@sum </span><span style="color:blue;">INT<br />
SELECT </span><span style="color:#434343;">@sum </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sum </span><span style="color:blue;">= </span><span style="color:#434343;">@sum </span><span style="color:gray;">+ </span><span style="color:black;">num </span><span style="color:blue;">FROM </span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">1 [num] </span><span style="color:blue;">UNION SELECT </span><span style="color:black;">2 [num]<br />
</span><span style="color:gray;">) </span><span style="color:black;">[a]<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sum </span><span style="color:black;">WithoutOrderBy<br />
GO</span></code></p>
<p style="text-align:justify;">Let us see the result when we run the above two queries with and without ORDER BY clause.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/orderby.jpg" alt="" width="370" height="442" /></p>
<p style="text-align:justify;">Again, it is interesting to see how results are different from each other when there is only change of inclusion of ORDER BY clause. Bob has explained why this is happening in his comment earlier. He also explains further in another comment in the same article that.</p>
<p style="text-align:justify;">Comment from <strong><a href="http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/#comment-56106" target="_blank">Bob</a></strong>:</p>
<p style="padding-left:30px;text-align:justify;">One more item to note is that if you built:</p>
<p style="padding-left:30px;text-align:justify;">SELECT @Str0 = @Str0 + C1 FROM T1</p>
<p style="padding-left:30px;text-align:justify;">into a table expression (i.e. VIEW, FUNCTION, FROM (SELECT)), you may get the results you want over and over until the one day where you call the view or function with the combination of syntax that triggers the unexpected behavoir.</p>
<p style="padding-left:30px;text-align:justify;"><em>pinaldave,</em></p>
<p style="padding-left:30px;text-align:justify;"><em><strong>On my final point</strong>, I think it’s unclear/weak. I’d like to add that the most clear reason as to why you can’t expect to get AB or BA, but might in fact get just A or just B, is that the construct @=@ +col is non-deterministic and therefore, for the same range of input values, is not guaranteed to produce the same result in every instance.</em></p>
<p style="text-align:justify;"><strong>Bob</strong>, Thank you very much for excellent explanation and your participation in the community.</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, Readers Contribution, SQL, SQL Authority, SQL Index, SQL Puzzle, SQL Query, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology Tagged: SQL View <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6930/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6930/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6930/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6930/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6930/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6930&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/29/sql-server-interesting-observation-execution-plan-and-results-of-aggregate-concatenation-queries/feed/</wfw:commentRss>
		<slash:comments>2</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/orderby.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Find Gaps in The Sequence</title>
		<link>http://blog.sqlauthority.com/2009/09/06/sql-server-find-gaps-in-the-sequence/</link>
		<comments>http://blog.sqlauthority.com/2009/09/06/sql-server-find-gaps-in-the-sequence/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 01:30:26 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></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[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Identity]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6723</guid>
		<description><![CDATA[I have previously written two articles on the subject of missing identity and both are very well received by community. I had great fun to write article as many SQL Server expert participated in both the articles. Expert Imran Mohammed had provided excellent script to find missing identity. Please read both the articles for additional [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6723&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I have previously written two articles on the subject of missing identity and both are very well received by community. I had great fun to write article as many SQL Server expert participated in both the articles. Expert <strong>Imran Mohammed </strong>had provided excellent script to find missing identity. Please read both the articles for additional information. <strong><br />
</strong></p>
<p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/08/11/sql-server-discussion-effect-of-missing-identity-on-system-real-world-scenario/" target="_blank">SQL SERVER – Discussion – Effect of Missing Identity on System – Real World Scenario</a><br />
</strong>
</p>
<p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/" target="_blank">SQL SERVER – List All Missing Identity Values of Table in Database</a></strong></p>
<p style="text-align:justify;">Well what really interesting is that another user asked similar question to find gaps in sequence. Two different expert Brian and Tejas responded with excellent solution. Let us go over questions and their solutions.</p>
<p style="text-align:justify;"><strong><a href="http://www.pinaldave.com/best-sql-server-download.cfm?Download=Find_Gaps_in_The_Sequence" target="_blank">Download script used in this article</a></strong></p>
<p style="text-align:justify;"><strong>Question by <a href="http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/#comment-54724" target="_blank">Enrico</a></strong></p>
<p style="padding-left:30px;text-align:justify;"><em>Hi Pinal/Folks,</em></p>
<p style="padding-left:30px;text-align:justify;"><em>Can anyone please help me? I am stunned at this one.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>Let’s say I have the following records:</em></p>
<p style="padding-left:30px;text-align:justify;"><em>INV0096<br />
INV0097<br />
INV0099<br />
INV0100<br />
INV0102<br />
INV0103</em>
</p>
<p style="padding-left:30px;text-align:justify;"><em>How can I generate a SQL Script that will show me the gaps in the sequence?</em></p>
<p style="padding-left:30px;text-align:justify;"><em>In such a way that the results will give me INV0098 and INV0101.<br />
Or even just the number 98, and 101.</em>
</p>
<p style="padding-left:30px;text-align:justify;"><em>Thank you so much for your time.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>Best regards,</em></p>
<p style="padding-left:30px;text-align:justify;"><em>Enrico</em></p>
<p style="text-align:justify;"><strong>First Solution by <a href="http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/#comment-54734" target="_blank">Brian Tkatch</a></strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/*<br />
Brian Tkatch Solution 1<br />
*/<br />
</span><span style="color:blue;">WITH<br />
</span><span style="color:black;">Data</span><span style="color:gray;">(</span><span style="color:black;">Datum</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0096' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0097' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0099' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0100' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0102' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0103'<br />
</span><span style="color:gray;">),<br />
</span><span style="color:black;">CTE<br />
</span><span style="color:blue;">AS<br />
</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:blue;">MIN</span><span style="color:gray;">(</span><span style="color:black;">Datum</span><span style="color:gray;">), </span><span style="color:black;">4</span><span style="color:gray;">, </span><span style="color:black;">4</span><span style="color:gray;">) </span><span style="color:blue;">AS INT</span><span style="color:gray;">) </span><span style="color:black;">Start</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">(</span><span style="color:black;">Datum</span><span style="color:gray;">), </span><span style="color:black;">4</span><span style="color:gray;">, </span><span style="color:black;">4</span><span style="color:gray;">) </span><span style="color:blue;">AS INT</span><span style="color:gray;">) </span><span style="color:black;">Finish<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">Data<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:black;">Start </span><span style="color:gray;">+ </span><span style="color:black;">1</span><span style="color:gray;">,<br />
</span><span style="color:black;">Finish<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">CTE<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:black;">Start </span><span style="color:gray;">&lt; </span><span style="color:black;">Finish<br />
</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:black;">Common.Formatted<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">CTE<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY</span><span style="color:gray;">(</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV' </span><span style="color:gray;">+ </span><span style="color:magenta;">RIGHT</span><span style="color:gray;">(</span><span style="color:red;">'0000' </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:black;">Start </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">4</span><span style="color:gray;">)), </span><span style="color:black;">4</span><span style="color:gray;">)) </span><span style="color:black;">Common</span><span style="color:gray;">(</span><span style="color:black;">Formatted</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:gray;">NOT EXISTS<br />
(<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">Data<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:black;">Data.Datum </span><span style="color:blue;">= </span><span style="color:black;">Common.Formatted<br />
</span><span style="color:gray;">)<br />
</span><span style="color:blue;">OPTION<br />
</span><span style="color:gray;">(</span><span style="color:black;">MAXRECURSION 0</span><span style="color:gray;">);</span></code>
</p>
<p style="text-align:justify;"><strong>Second Solution by <a href="http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/#comment-54734" target="_blank">Brian Tkatch</a></strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/*<br />
Brian Tkatch Solution 2<br />
The CROSS APPLY is just nice, but not required. Without it, the query is very similar:<br />
*/<br />
</span><span style="color:blue;">WITH<br />
</span><span style="color:black;">Data</span><span style="color:gray;">(</span><span style="color:black;">Datum</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0096' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0097' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0099' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0100' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0102' </span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0103'<br />
</span><span style="color:gray;">),<br />
</span><span style="color:black;">CTE<br />
</span><span style="color:blue;">AS<br />
</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:blue;">MIN</span><span style="color:gray;">(</span><span style="color:black;">Datum</span><span style="color:gray;">), </span><span style="color:black;">4</span><span style="color:gray;">, </span><span style="color:black;">4</span><span style="color:gray;">) </span><span style="color:blue;">AS INT</span><span style="color:gray;">) </span><span style="color:black;">Start</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">(</span><span style="color:black;">Datum</span><span style="color:gray;">), </span><span style="color:black;">4</span><span style="color:gray;">, </span><span style="color:black;">4</span><span style="color:gray;">) </span><span style="color:blue;">AS INT</span><span style="color:gray;">) </span><span style="color:black;">Finish<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">Data<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:black;">Start </span><span style="color:gray;">+ </span><span style="color:black;">1</span><span style="color:gray;">,<br />
</span><span style="color:black;">Finish<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">CTE<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:black;">Start </span><span style="color:gray;">&lt; </span><span style="color:black;">Finish<br />
</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:red;">'INV' </span><span style="color:gray;">+ </span><span style="color:magenta;">RIGHT</span><span style="color:gray;">(</span><span style="color:red;">'0000' </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:black;">Start </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">4</span><span style="color:gray;">)), </span><span style="color:black;">4</span><span style="color:gray;">)<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">CTE<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:gray;">NOT EXISTS<br />
(<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">Data<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:black;">Data.Datum </span><span style="color:blue;">= </span><span style="color:red;">'INV' </span><span style="color:gray;">+ </span><span style="color:magenta;">RIGHT</span><span style="color:gray;">(</span><span style="color:red;">'0000' </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:black;">Start </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">4</span><span style="color:gray;">)), </span><span style="color:black;">4</span><span style="color:gray;">)<br />
)<br />
</span><span style="color:blue;">OPTION<br />
</span><span style="color:gray;">(</span><span style="color:black;">MAXRECURSION 0</span><span style="color:gray;">);</span></code>
</p>
<p style="text-align:justify;"><strong>Third Solution by <a href="http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/#comment-54736" target="_blank">Tejas Shah</a></strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/*<br />
Tejas Shah Solution 3<br />
*/<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Test </span><span style="color:blue;">TABLE </span><span style="color:gray;">(</span><span style="color:black;">Data </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">))<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">@test<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0096'<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0097'<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0099'<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0100'<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0102'<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0103'<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0106'<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'INV0110'<br />
</span><span style="color:gray;">;</span><span style="color:blue;">WITH </span><span style="color:black;">cte1 </span><span style="color:blue;">AS</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">RIGHT</span><span style="color:gray;">(</span><span style="color:black;">Data</span><span style="color:gray;">,</span><span style="color:black;">4</span><span style="color:gray;">) </span><span style="color:blue;">AS INT</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">RowID<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">@Test<br />
</span><span style="color:gray;">), </span><span style="color:black;">Missing </span><span style="color:blue;">AS</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT MIN</span><span style="color:gray;">(</span><span style="color:black;">RowID</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">MissNum</span><span style="color:gray;">,<br />
</span><span style="color:blue;">MAX</span><span style="color:gray;">(</span><span style="color:black;">RowID</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">MaxID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Cte1<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">MissNum </span><span style="color:gray;">+ </span><span style="color:black;">1</span><span style="color:gray;">,<br />
</span><span style="color:black;">MaxID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Missing<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">MissNum </span><span style="color:gray;">&lt; </span><span style="color:black;">MaxID<br />
</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">missnum<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Missing<br />
</span><span style="color:magenta;">LEFT </span><span style="color:blue;">JOIN </span><span style="color:black;">cte1 tt </span><span style="color:blue;">ON </span><span style="color:black;">tt.Rowid </span><span style="color:blue;">= </span><span style="color:black;">Missing.MissNum<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">tt.Rowid </span><span style="color:blue;">IS </span><span style="color:gray;">NULL<br />
</span><span style="color:blue;">OPTION </span><span style="color:gray;">(</span><span style="color:black;">MAXRECURSION 0</span><span style="color:gray;">);<br />
</span></code>
</p>
<p style="text-align:justify;">Let me know if you know any other trick to achieve the same.</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, Readers Contribution, Readers Question, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology Tagged: Identity <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6723/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6723/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6723/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6723/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6723/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6723/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6723/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6723/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6723/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6723/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6723&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/06/sql-server-find-gaps-in-the-sequence/feed/</wfw:commentRss>
		<slash:comments>6</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; Discussion &#8211; Effect of Missing Identity on System &#8211; Real World Scenario</title>
		<link>http://blog.sqlauthority.com/2009/08/11/sql-server-discussion-effect-of-missing-identity-on-system-real-world-scenario/</link>
		<comments>http://blog.sqlauthority.com/2009/08/11/sql-server-discussion-effect-of-missing-identity-on-system-real-world-scenario/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 01:30:13 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6524</guid>
		<description><![CDATA[About a week ago, SQL Server Expert, Imran Mohammed, provided a script, which will list all the missing identity values of a table in a database. In this post, I asked my readers if any could write a similar or better script. The results were interesting. While no one provided a new script, my question [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6524&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">About a week ago, SQL Server Expert, <strong>Imran Mohammed,</strong> provided a script, which will list all the missing identity values of a table in a database. In this <a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/">post</a>, I asked my readers if any could write a similar or better script. The results were interesting. While no one provided a new script, my question sparked a very active <a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/">discussion</a> that is still ongoing.</p>
<p style="text-align:justify;">When providing the script, Imran asked me if I knew of any specific circumstances in which this kind of query could be useful, as he could not think of an instance where it would be necessary to find a missing identity. I was unable to think of a single reason for listing missing identities in a table. I posted Imran&#8217;s script on the assumption that someone would come up with an improved script, but as mentioned earlier, nobody did. Instead, we have been able to follow a very interesting discussion on subject of the need, if any, for listing Missing Identity values.</p>
<p style="text-align:justify;">So, the question is this: &#8220;<strong><em>Do you know a real-world scenario where a Missing Identity value in any table can create problems?</em></strong>&#8220;</p>
<p style="text-align:justify;">I have already received some extremely interesting comments from many experts, and all have posed the above question in one form or another. At this moment, I am still trying to think of an example from my own experience, but have yet to find one. Imran has since come up with one good example. Here is what he and other experts have suggested so far.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comment-54117" target="_blank"><strong>Jacob Sebastian</strong></a> &#8211; IDENTITY values are not expected to be sequential and there are all chances of having missing identity values, the most common cause is transaction rollbacks.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comment-54139" target="_blank"><strong>Simon Worth</strong></a> &#8211; The identity column is basically just a random number – even though they come sequentially. A developer making an assumption that the next record inserted will have an identity that is 1 more than the last inserted record. And if this is the case – then there are flaws in the logic of the developer.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comment-54158" target="_blank"><strong>Jacob Sebastian</strong></a> &#8211; What if the value in my table is 1, 2, 3, 5, 6 etc where “4″ is missing from the sequence. So what is the importance of knowing whether a table has missing identity values or not?</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comment-54184" target="_blank"><strong>Imran Mohammed</strong></a> &#8211; If you use Identity property as your most unique column and Transaction Identifier, then definitely you would want to know why few transaction did not completely, Is there any specific fashion these transaction fails (Can be found out looking at missing values of identity)&#8230; Could be helpful to debug.</p>
<p style="text-align:justify;">Now it is your turn. Let us have your thoughts.</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 Database, DBA, Pinal Dave, Readers Contribution, Readers Question, SQL, SQL Authority, SQL Constraint and Keys, SQL Index, SQL Puzzle, SQL Query, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6524/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6524&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/11/sql-server-discussion-effect-of-missing-identity-on-system-real-world-scenario/feed/</wfw:commentRss>
		<slash:comments>6</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; Author&#8217;s Birthday &#8211; Top 7 Commenters &#8211; Volunteers</title>
		<link>http://blog.sqlauthority.com/2009/07/30/sqlauthority-news-authors-birthday-top-7-commenters-volunteers/</link>
		<comments>http://blog.sqlauthority.com/2009/07/30/sqlauthority-news-authors-birthday-top-7-commenters-volunteers/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 01:30:18 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[About Me]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6060</guid>
		<description><![CDATA[Today is July 30 and I am very happy; it’s my Birthday, celebration time!!! The most common question I receive on my every birthday is -what are my plans for birthday. Let me share my plans here today. Additionally, if you are interested to know when SQL Server was born read my post SQLAuthority News [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6060&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Today is <strong>July 30</strong> and I am very happy; it’s <strong>my Birthday</strong>, celebration time!!! The most common question I receive on my every birthday is -what are my plans for birthday. Let me share my plans here today. Additionally, if you are interested to know when SQL Server was born read my post <strong><a href="http://blog.sqlauthority.com/2008/07/30/sqlauthority-news-author-birthday-sql-server-birthday/" target="_blank">SQLAuthority News – Author BirthDay – SQL Server Birthday</a></strong>.</p>
<p style="text-align:justify;">My first plan is that I am going to take a break from blogging on anything technical today and spend more time with my family.</p>
<p style="text-align:justify;">Let me tell you about my second plan. I am very much pleased and encouraged with active participation from many of you on this blog. I have received so far more than 10s of thousands of comments on my blog. These comments are open for you all to read and you can use them in any fashion that can help you out. Without good participation there is no life in any community, whether it is offline or online.</p>
<p style="text-align:justify;">For the same reason, I have introduced Top 7 Commenters section in the side bar of SQLAuthority.com. There are many active users who have been participating for a long time. One of them I just recognized is Imran Mohammed. This SQL Expert has been extremely helpful to the community and has been providing comprehensive answers to hundreds of questions. Hats Off to you Imran! I totally appreciate your knowledge and dedication to SQL community. Without passion and love toward helping community, this is absolutely not possible.</p>
<p>You can subscribe to <a href="http://feedproxy.google.com/SQLAuthority" target="_blank">SQLAuthority.com feed</a>, which will display all the new posts of my blog as they are published.</p>
<p>You can subscribe to<a href="http://blog.sqlauthority.com/comments/feed/" target="_blank"> SQLAuthority.com comments</a>, which will show all the new comments posted on the blog as they are published.</p>
<p style="text-align:justify;">If you prefer to receive <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=872428" target="_blank">SQLAuthority.com articles in email</a>, you will get all the fresh posts in email.</p>
<p style="text-align:justify;">There is no automated feature for top commenters where I host, so I will have to calculate this manually. I will keep it updated on weekly basis. Every week we will see new names there. First column is number of post, and second column is number name with link to experts website or blog or email.</p>
<p style="text-align:justify;">Every day I receive a couple of emails about starting a forum on SQLAuthority.com. I do plan to start the forum in future. Currently, there are plenty of very good forums on the web. SQLAuthority.com is a blog and below every blog post there is a discussion related to the subject discussed in the blog post.</p>
<p style="text-align:justify;">SQLAuthority.com is all about community and people who are passionate about SQL. Everyone is welcome to participate here. There are many ways to participate.</p>
<p style="text-align:justify;">
<ul style="text-align:justify;">
<li>Discussing blog post</li>
<li>Helping user who have posted their issues on blog</li>
<li>Asking questions</li>
<li>Writing Guest Post</li>
<li>Submitting useful SQL Scripts</li>
<li>Reviewing any Microsoft-related products</li>
<li>Reviewing Books</li>
</ul>
<p style="text-align:justify;">Let me know if you have any other useful and interesting suggestions on how I can involve YOU more in my efforts to take SQL community to the next level.</p>
<p style="text-align:justify;">If you are interested in participating in volunteer program do send me email at pinal &#8216;at&#8217; SQLAuthority.com and we can discuss something out.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.sqlauthority.com</a>)</strong></p>
Posted in About Me, Database, DBA, Pinal Dave, Readers Contribution, Readers Question, Software Development, SQL, SQL Authority, SQL Query, 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/6060/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6060/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6060/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6060/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6060/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6060/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6060/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6060/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6060/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6060/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6060&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/07/30/sqlauthority-news-authors-birthday-top-7-commenters-volunteers/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; List All Missing Identity Values of Table in Database</title>
		<link>http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/</link>
		<comments>http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 01:30:11 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></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[Identity]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6339</guid>
		<description><![CDATA[The best part of any blog is when readers ask each other questions. Better still, is when a reader takes the time to provide a detailed response.
A few days ago, one of my readers, Yasmin, asked a very interesting question:
How we can find the list of tables whose identity was missed (not is sequential order) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6339&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">The best part of any blog is when readers ask each other questions. Better still, is when a reader takes the time to provide a detailed response.</p>
<p style="text-align:justify;">A few days ago, one of my readers, <a href="http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-53353" target="_blank">Yasmin, </a>asked a very interesting question:</p>
<p style="text-align:justify;"><strong><em>How we can find the list of tables whose identity was missed (not is sequential order) within the entire database?</em></strong></p>
<p style="text-align:justify;">A big thank you to SQL Server Expert, <strong>Imran Mohammed</strong>, for his excellent response to this question. He also provided an extremely impressive script, which is well described and contains inline comments.</p>
<p style="text-align:justify;">This script is well worth keeping in your archive for future reference.</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=Get_Missing_Identity_Value_Information" target="_blank"><strong>Download Script List All Missing Identity Values of Table in Database</strong></a></p>
<p style="text-align:justify;">If you and use the script, please comment here and let me know about your experience.</p>
<p style="text-align:justify;">If you know any other way that this can be accomplished or have a different solution, please post your comment here, or send me an email and I will publish it with due credit.</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, Readers Contribution, SQL, SQL Authority, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology Tagged: Identity <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6339/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6339&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/feed/</wfw:commentRss>
		<slash:comments>28</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; SQL Server Value Calculator</title>
		<link>http://blog.sqlauthority.com/2009/07/22/sqlauthority-news-sql-server-value-calculator/</link>
		<comments>http://blog.sqlauthority.com/2009/07/22/sqlauthority-news-sql-server-value-calculator/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 01:30:58 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6133</guid>
		<description><![CDATA[I have been using twitter for quite some time now (follow me at @pinaldave). In twitter world very often I find something interesting shared by my friends there. SQL Server Expert and Microsoft Evanglist Vinod Kumar has twitted very interesting detail linking to SQL Server Value Calculator. The web version of this tool is created [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6133&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I have been using twitter for quite some time now (follow me at <strong><a href="http://twitter.com/pinaldave" target="_blank">@pinaldave</a></strong>). In twitter world very often I find something interesting shared by my friends there. SQL Server Expert and Microsoft Evanglist <a href="http://www.extremeexperts.com/General/Home/Homepage.aspx" target="_blank">Vinod Kumar</a> has twitted very interesting detail linking to <a href="http://www.microsoft.com/sqlserver/2008/en/us/value-calc.aspx" target="_blank">SQL Server Value Calculator</a>. The web version of this tool is created in Silver Light and looks very cool and gives impression of PC Game Sims at first moment.</p>
<p style="text-align:justify;">This tool calculates Total Estimate Saving if SQL Server is used in any organization. It takes into consideration Total IT team members, Bandwidth, Servers, Security, Reports, Audits, Supports Calls and Encryption in its calculation. This tool provides a discussion framework and is designed to stimulate conversation regarding the potential costs and benefits of deploying SQL Server 2008. As a result, all inputs can be changed to estimate benefit and cost data. Default values are pre-populated to facilitate discussion and are meant to be changed as outlined below.</p>
<p style="text-align:justify;">You can also download the full SQL Server Value Calculator which is in Excel from the same screen.  When I downloaded the Excel I was amazed at what a tremendous capacity of MS Excel has and how many people are really using it to its full potential. Microsoft has used two of its  own technologies &#8211; MS Excel and Silverlight to show how good SQL Server is.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/sqlcalc.jpg" alt="" width="500" height="322" /></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.sqlauthority.com</a>)</strong></p>
<p style="text-align:justify;">
Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Documentation, SQL Query, SQL Server, SQL Tips and Tricks, SQL Utility, SQLAuthority News, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6133&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/07/22/sqlauthority-news-sql-server-value-calculator/feed/</wfw:commentRss>
		<slash:comments>2</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/sqlcalc.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Maximum Number of Index per Table</title>
		<link>http://blog.sqlauthority.com/2009/06/29/sql-server-maximum-number-of-index-per-table/</link>
		<comments>http://blog.sqlauthority.com/2009/06/29/sql-server-maximum-number-of-index-per-table/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 01:30:05 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></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://blog.sqlauthority.com/?p=5733</guid>
		<description><![CDATA[TechEd on Road Ahmedabad, June 20, 2009, was a huge success. This grand event saw over 200 attendees actively participating in the sessions. We had attendees traveling from far and wide, including Delhi, Mumbai, Jaipur, Kerala, Baroda, Himmatnagar, Rajkot, among other cities from India. This enthusiastic participation made the event truly grand. It was a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5733&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/06/22/sqlauthority-news-teched-on-road-ahmedabad-june-20-2009-an-astounding-success/" target="_blank">TechEd on Road Ahmedabad</a></strong>, June 20, 2009, was a huge success. This grand event saw over 200 attendees actively participating in the sessions. We had attendees traveling from far and wide, including Delhi, Mumbai, Jaipur, Kerala, Baroda, Himmatnagar, Rajkot, among other cities from India. This enthusiastic participation made the event truly grand. It was a moment of bliss for me as I had not anticipated such tremendous positive response!</p>
<p style="text-align:justify;">Although the Official time to commence the event was at 1:45 PM we were really excited to see the attendees entering the hall before the official time. We were more than happy to quickly arrange a special session for those attendees who came in early to keep them engaged. They won loads of gifts while waiting for the official sessions to start. We had a brainstorming quiz session. I was happy to see that people in Ahmedabad are now taking keen interest in enhancing their knowledge.</p>
<p style="text-align:justify;">One of the questions was &#8211; <strong>What is the maximum number of Index per table? </strong>I received lots of answers to this question but only two answers are correct. Let us now take a look at them.</p>
<p style="text-align:justify;"><strong>For SQL Server 2005:</strong><br />
1 Clustered Index + 249 Nonclustered Index = 250 Index<br />
<a href="http://msdn.microsoft.com/en-us/library/ms143432(SQL.90).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms143432(SQL.90).aspx</a></p>
<p style="text-align:justify;"><strong>For SQL Server 2008:</strong><br />
1 Clustered Index + 999 Nonclustered Index = 1000 Index<br />
<a href="http://msdn.microsoft.com/en-us/library/ms143432.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms143432.aspx</a>
</p>
<p style="text-align:justify;">I would like to thank one of the attendees of Ahmedabad TechEd Kruti Kansara for the above comment.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
Posted in Pinal Dave, Readers Contribution, Readers Question, SQL, SQL Authority, SQL Index, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5733/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5733&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/29/sql-server-maximum-number-of-index-per-table/feed/</wfw:commentRss>
		<slash:comments>13</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; Interesting Observation of Logon Trigger On All Servers &#8211; Solution</title>
		<link>http://blog.sqlauthority.com/2009/06/26/sql-server-interesting-observation-of-logon-trigger-on-all-servers-solution/</link>
		<comments>http://blog.sqlauthority.com/2009/06/26/sql-server-interesting-observation-of-logon-trigger-on-all-servers-solution/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 01:30:14 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Puzzle]]></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[SQL Trigger]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5718</guid>
		<description><![CDATA[Does the title of this post trigger your mind? If you all remember, a few days back I had written an article on my interesting observation regarding logon triggers. I would advise you to first read SQL SERVER – Interesting Observation of Logon Trigger On All Servers before continuing with this article further to have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5718&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Does the title of this post trigger your mind? If you all remember, a few days back I had written an article on my interesting observation regarding logon triggers. I would advise you to first read <strong><a href="http://blog.sqlauthority.com/2009/05/27/sql-server-interesting-observation-of-logon-trigger-on-all-servers/" target="_blank">SQL SERVER – Interesting Observation of Logon Trigger On All Servers</a></strong> before continuing with this article further to have a complete idea of the subject.</p>
<p style="text-align:justify;">The question I put forth in my previous article was &#8211; In single login why the trigger fires multiple times; it should be fired only once. I received numerous answers in thread as well as in my MVP private news group. Now, let us discuss the answer for the same.</p>
<p style="text-align:justify;">The answer is – <strong>It happens because multiple SQL Server services are running as well as intellisense is turned on. </strong></p>
<p style="text-align:justify;">Let us verify the above answer.</p>
<p style="text-align:justify;">First, run the following script to create database and logon Audit table.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Create Audit Database */<br />
</span><span style="color:blue;">CREATE DATABASE </span><span style="color:black;">AuditDb<br />
GO<br />
</span><span style="color:blue;">USE </span><span style="color:black;">AuditDb<br />
GO<br />
</span><span style="color:green;">/* Create Audit Table */<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">ServerLogonHistory<br />
</span><span style="color:gray;">(</span><span style="color:black;">SystemUser </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">512</span><span style="color:gray;">),<br />
</span><span style="color:black;">DBUser </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">512</span><span style="color:gray;">),<br />
</span><span style="color:black;">SPID </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">LogonTime DATETIME</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* Create Logon Trigger */<br />
</span><span style="color:blue;">CREATE TRIGGER </span><span style="color:black;">Tr_ServerLogon<br />
</span><span style="color:blue;">ON </span><span style="color:gray;">ALL </span><span style="color:black;">SERVER </span><span style="color:blue;">FOR </span><span style="color:black;">LOGON<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
INSERT INTO </span><span style="color:black;">AuditDb.dbo.ServerLogonHistory<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">SYSTEM_USER</span><span style="color:gray;">,</span><span style="color:magenta;">USER</span><span style="color:gray;">,</span><span style="color:#434343;">@@SPID</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code>
</p>
<p style="text-align:justify;">After that, disable all the other SQL Server Services as delineated in the image below using SQL Server Configuration Manager.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/disableservices.png" alt="" width="456" height="277" /></p>
<p style="text-align:justify;">Next, try to logon to the system only one more time.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/loginscreen.png" alt="" width="426" height="319" /></p>
<p style="text-align:justify;">Check the audit table again to verify if there is a single entry for single login.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/singlelogin.png" alt="" width="428" height="594" /></p>
<p style="text-align:justify;">I would once again like to thank all of you for active participation and coming up with wonderful suggestions and answers. Let me have your opinion on this observation.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Puzzle, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQL Trigger, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5718/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5718/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5718/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5718/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5718/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5718/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5718/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5718/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5718/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5718/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5718&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/26/sql-server-interesting-observation-of-logon-trigger-on-all-servers-solution/feed/</wfw:commentRss>
		<slash:comments>6</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/disableservices.png" medium="image" />

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

		<media:content url="http://www.pinaldave.com/bimg/singlelogin.png" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Performance Counters from System Views &#8211; By Kevin Mckenna</title>
		<link>http://blog.sqlauthority.com/2009/06/10/sql-server-performance-counters-from-system-views-by-kevin-mckenna/</link>
		<comments>http://blog.sqlauthority.com/2009/06/10/sql-server-performance-counters-from-system-views-by-kevin-mckenna/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 01:30:56 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></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/?p=5407</guid>
		<description><![CDATA[I just love social media and all the new concepts of Web 2.0. There are bloggers who are overwhelmed by the new concepts of technology and are not able to keep pace with it. But I like taking such challenges. Twitter has acquired tremendous popularity nowadays and just like everybody else I am also fond [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5407&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I just love social media and all the new concepts of Web 2.0. There are bloggers who are overwhelmed by the new concepts of technology and are not able to keep pace with it. But I like taking such challenges. Twitter has acquired tremendous popularity nowadays and just like everybody else I am also fond of this latest vogue. You can <a href="http://twitter.com/pinaldave" target="_blank">follow me</a> at Twitter <a href="http://twitter.com/pinaldave" target="_blank">here</a>. Through twitter I am getting to meet people like me and it’s a great experience interacting with them. I met SQL and .NET expert <strong><a href="http://twitter.com/kev_mck" target="_blank"><strong>Kevin Mckenna</strong></a></strong> on twitter itself.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/kevmck.jpg" alt="" width="200" height="139" /></p>
<p style="text-align:justify;">Kevin is originally from Liverpool, England, and moved to the US in December 2005. He is a DBA for a large warehousing and logistics company based in the US. He has been developing software with SQL backends for approximately 6-7 years, and has been administrating SQL and Oracle databases for the past 4 years.</p>
<p style="text-align:justify;">He is married and has 2 children.  He is a huge football (soccer for the Americans) fan, and when he is not working, he likes spending his time either reading or playing on <a href="http://twitter.com/kev_mck" target="_blank">twitter</a>.</p>
<p style="text-align:justify;">He has recently sent me a very interesting note on Performance Counters from System Views. I really enjoyed reading it and with his permission I am publishing the content here. Let me have your opinion on this.</p>
<p style="text-align:justify;">Many of you are not aware of this fact that access to performance information is readily available in SQL Server and that too without querying performance counters using a custom application or via perfmon. Till now, this fact has remained undisclosed but through this post I would like to explain you can easily access SQL Server performance counter information.</p>
<p style="text-align:justify;">Without putting much effort you will come across the system view <strong>sys.dm_os_performance_counters</strong>. As the name suggests, this provides you easy access to the SQL Server performance counter information that is passed on to perfmon, but you can get at it via tsql.</p>
<p style="text-align:justify;">You can start with a few simple steps:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT</span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_performance_counters</span></code></p>
<p style="text-align:justify;">This returns 701 rows of data on the test machine, with information from Buffer Manager, Buffer Partition, Buffer Node, General Statistics, Locks, and so forth.</p>
<p style="text-align:justify;">I’ll try to make you all understand by making it a bit more simple. Here, we will concentrate on Buffer Manager.</p>
<p style="text-align:justify;">Please note that if you have an instance name, the object name will be MSSQLlt;instance name&gt;: instead of SQLServer:</p>
<p style="text-align:justify;">The next step is</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT</span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_performance_counters </span><span style="color:blue;">WHERE </span><span style="color:magenta;">OBJECT_NAME </span><span style="color:blue;">= </span><span style="color:red;">'SQLServer:Buffer Manager'</span></code></p>
<p style="text-align:justify;">The following screen will be displayed.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/Pcount.png" alt="" width="547" height="449" /><span>XX</span></p>
<p style="text-align:justify;">As you all can notice, what is displayed above via tsql is similar to what is available via perfmon</p>
<p style="text-align:justify;">Let’s take a look at the columns returned:</p>
<p style="text-align:justify;"><strong>field name</strong> data type Description<br />
<strong>object_name</strong> nchar(128) Category to which this counter belongs<br />
<strong>counter_name</strong> nchar(128) Name of the counter<br />
<strong>instance_name </strong>nchar(128) Name of the specific instance of the counter. Often contains the database name<br />
<strong>cntr_value</strong> bigint Current value of the counter<br />
<strong>cntr_type</strong> int Type of counter as defined by the Windows performance architecture
</p>
<p style="text-align:justify;">Now, if you all are wondering what can be done with this information then let me tell you that you have a few things options. We can create a job that will sample a particular value on a timed basis and add it to a table, and view an average value from it. Another option is to just take a glance at it for peace of mind!</p>
<p style="text-align:justify;">One of the most useful things we could derive from this however is trend information.  For example, let’s chart the number of Active Transactions during the work day.</p>
<p style="text-align:justify;">We will start with creating a table, as given below.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE TABLE </span><span style="color:black;">ActiveTrans_sqlGenus </span><span style="color:gray;">(<br />
</span><span style="color:black;">obj_name </span><span style="color:magenta;">NCHAR</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">),<br />
</span><span style="color:black;">counter_name </span><span style="color:magenta;">NCHAR</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">),<br />
</span><span style="color:black;">instance_name </span><span style="color:magenta;">NCHAR</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">),<br />
</span><span style="color:black;">cntr_value bigint</span><span style="color:gray;">,<br />
</span><span style="color:black;">cntr_type </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">datestamp datetime<br />
</span><span style="color:gray;">)</span></code>
</p>
<p style="text-align:justify;">We can then fill up this table on a timed basis:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">INSERT INTO </span><span style="color:black;">ActiveTrans_sqlGenus<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:magenta;">OBJECT_NAME</span><span style="color:gray;">, </span><span style="color:black;">counter_name</span><span style="color:gray;">, </span><span style="color:black;">instance_name</span><span style="color:gray;">, </span><span style="color:black;">cntr_value</span><span style="color:gray;">,<br />
</span><span style="color:black;">cntr_type</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">sys.dm_os_performance_counters<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:magenta;">OBJECT_NAME </span><span style="color:blue;">= </span><span style="color:red;">'SQLServer:Databases'<br />
</span><span style="color:black;">ANDcounter_name </span><span style="color:blue;">= </span><span style="color:red;">'Active Transactions'<br />
</span><span style="color:black;">ANDinstance_name </span><span style="color:blue;">= </span><span style="color:red;">'sqlGenus'</span></code>
</p>
<p style="text-align:justify;">Here, let’s assume that we are inserting into this table on a consistent basis. We can then issue the following command:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT</span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">ActiveTrans_sqlGenus<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">datestamp </span><span style="color:gray;">BETWEEN </span><span style="color:red;">'06/02/2009 09:00' </span><span style="color:gray;">AND </span><span style="color:red;">'06/02/2009 17:00'</span></code>
</p>
<p style="text-align:justify;">After that, we can retrieve all the entries between 9am and 5pm, our fictitious work day.</p>
<p style="text-align:justify;">We could manipulate this data even further, averaging out the values, pulling the MAX and MIN and so on.</p>
<p style="text-align:justify;">Obviously, this is a very simple example, and certainly not the best way to store this information over a period of time. However, with some digging into just what you need, you can provide access to your SQL Server performance in a remarkably simple manner.</p>
<p style="text-align:justify;">The biggest disappointment in obtaining this information from SQL Server’s system views is that it only provides SQL Server information, so we do not receive information like Processor, Network and Disk information.  These values still need to be pulled via Performance Counters.  But despite this negative aspect, this view will provide ample usable information to keep your database in an excellent shape.</p>
<p style="text-align:justify;">
You can find more information on this system view from MSDN:
</p>
<p style="text-align:justify;"><a href="http://msdn.microsoft.com/en-us/library/ms187743%28SQL.90%29.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms187743(SQL.90).aspx</a></p>
<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 Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5407/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5407&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/10/sql-server-performance-counters-from-system-views-by-kevin-mckenna/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>

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

		<media:content url="http://www.pinaldave.com/bimg/Pcount.png" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 10 Reasons for Database Outsourcing</title>
		<link>http://blog.sqlauthority.com/2009/05/10/sql-server-10-reasons-for-database-outsourcing/</link>
		<comments>http://blog.sqlauthority.com/2009/05/10/sql-server-10-reasons-for-database-outsourcing/#comments</comments>
		<pubDate>Sun, 10 May 2009 01:30:10 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></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>
		<category><![CDATA[Outsourcing Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4885</guid>
		<description><![CDATA[10 Reasons for Database Outsourcing
While you may feel that your IT material is safe and handled effectively within your own company, these reasons may give you some perspective on why you may want to consider other options.
Cost Reduction &#8211; Perhaps the most popular reason to outsource your database is the overall reduction in cost that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4885&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><strong>10 Reasons for Database Outsourcing</strong></p>
<p style="text-align:justify;"><em>While you may feel that your IT material is safe and handled effectively within your own company, these reasons may give you some perspective on why you may want to consider other options.</em></p>
<p style="text-align:justify;"><strong>Cost Reduction</strong> &#8211; Perhaps the most popular reason to outsource your database is the overall reduction in cost that would benefit your company.  No longer do you have to pay people to check up and maintain your servers, verify that they have uninterrupted power supplies, and ensure their security from hackers.  By going with an IT company that does this exclusively, you can save money on your end because they make money by volume.</p>
<p style="text-align:justify;"><strong>Bigger Can Mean Better</strong> &#8211; Larger IT outsourcing companies are experts at what they do; there&#8217;s a reason they have made it to the top of the data storage field.  Not only will they have the resources to back up your data, perhaps multiple times, but they do business by serving many clients, which meant they have the power and money to get the latest technology.</p>
<p style="text-align:justify;"><strong>Newer Technology</strong> &#8211; Firms that specialize in storage can&#8217;t afford to let their systems go out of style or date because that could jeopardize their business.  Going with them means you won&#8217;t have to worry about constantly updating your systems.</p>
<p style="text-align:justify;"><strong>Reduction in Liability</strong> &#8211; Turning over this task to an expert also means a lot less worrying on your part.  All you have to do is make sure you are operating within a solid contract that protects you in the case of data loss.  Agree to a contract that puts you ahead in the case of a loss and you can sleep soundly knowing that your data is safe.</p>
<p style="text-align:justify;"><strong>Competition means Lower Prices Elsewhere as Well</strong> &#8211; Now that you are in a market where others are competing for your business, you&#8217;ll get to shop around and find the best deal in town.  In addition to the number one reason of lowering your overhead, competition also means that if you find you have gone with a company that doesn&#8217;t meet your needs you can switch.  Imagine making that mistake if you owned all your own equipment!</p>
<p style="text-align:justify;"><strong>More Effective Communication</strong> &#8211; If your company runs a database that needs to be accessed by multiple points, it will be easier for others to access and probably be faster for them to access as well.  Once again a good contract is key, but in most cases you can get more bandwidth access for your money by outsourcing, than you could by providing your own database connection.</p>
<p style="text-align:justify;"><strong>Better Security</strong> &#8211; On the other hand you will know your data is backed up by competition driven upgraded safeware.</p>
<p style="text-align:justify;"><strong>Standardization</strong> &#8211; What if your resource manager suddenly quits or is fired?  Outsourcing virtually guarantees that your information will be stored in a standard way, accessible consistently and without fear of security leaks.</p>
<p style="text-align:justify;"><strong>Cross-referencing with Third Party Information</strong> &#8211; In many cases it may be possible to have your information collated and cross-referenced with other information for a variety of needs.  Once again get a solid contract and fully understand your security requirements first.</p>
<p style="text-align:justify;"><strong>Removal of Duplicate or Incorrect Data</strong> &#8211; A final way outsourcing can help your database is a common option many companies will offer, which is the examination of your data in various ways as it is transferred.  Think of this as your businesses opportunity to &#8216;clean house,&#8217; and set out again with a fresh start.</p>
<p style="text-align:justify;">This post was contributed by <strong>Claire Webber</strong>, who writes about the <strong><a href="http://www.online-college-blog.com/">schools online</a></strong>. She welcomes your feedback at Claire.Webber1223 at gmail.com</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 Best Practices, Database, DBA, Readers Contribution, SQL, SQL Authority, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology Tagged: Outsourcing Technology <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4885/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4885/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4885/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4885/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4885/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4885/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4885/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4885/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4885/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4885/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4885&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/05/10/sql-server-10-reasons-for-database-outsourcing/feed/</wfw:commentRss>
		<slash:comments>6</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; Future of Business Intelligence and Databases &#8211; Article by Nupur Dave</title>
		<link>http://blog.sqlauthority.com/2009/05/08/sqlauthority-news-future-of-business-intelligence-and-databases-article-by-nupur-dave/</link>
		<comments>http://blog.sqlauthority.com/2009/05/08/sqlauthority-news-future-of-business-intelligence-and-databases-article-by-nupur-dave/#comments</comments>
		<pubDate>Fri, 08 May 2009 01:30:57 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Data Warehousing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></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=5013</guid>
		<description><![CDATA[This article is submitted by Nupur Dave
Future of Business Intelligence and Databases
The term business intelligence (BI) was coined by Howard Dresner in the early 1990s. He defined Business Intelligence as “a set of concepts and methodologies to improve decision making in business through use of facts and fact-based systems.” In a time when data warehousing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5013&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This article is submitted by <strong>Nupur Dave</strong></p>
<h2 style="text-align:justify;"><strong>Future of Business Intelligence and Databases</strong></h2>
<p style="text-align:justify;">The term business intelligence (BI) was coined by Howard Dresner in the early 1990s. He defined Business Intelligence as “a set of concepts and methodologies to improve decision making in business through use of facts and fact-based systems.” In a time when data warehousing was considered leading-edge he created the vision that led to the development of business intelligence, as it is known today.  The once visionary BI is now commonplace and in near future a momentous transformation is about to take place.</p>
<p style="text-align:justify;">BI is all set to bring information democracy where end users across an organization will be able to view information related to their segment. Further, with the rising consumer expectations there will be demand for capability requirements of BI as well.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/bi2.jpg" alt="" width="500" height="403" /></p>
<p style="text-align:justify;"><strong>Information Democracy with</strong><strong> </strong><strong>Business Intelligence</strong><strong></strong></p>
<p style="text-align:justify;">BI plays a crucial role in providing cost-effective, comprehensive insights into business processes that help organizations make informed, strategic decisions that assure enhanced business results. Not long ago, BI was the domain of statisticians and corporate analysts. Only the selected few could access BI. Today, BI is spreading to nearly every strata of organization, as companies attempt to provide critical data to business users who need it to perform their jobs. It is quite evident that BI is instrumental in bringing information democracy and it provides everyone the insights they require &#8211; delivering information to the right people at the right time across the enterprise. More and more organizations are expected to empower their employees with BI for productivity and operational gains.</p>
<p style="text-align:justify;"><strong>Business Intelligence</strong><strong> and Performance Management for competitive advantage</strong></p>
<p style="text-align:justify;">Today, when economic downturn is adversely affecting the world market, making insightful decisions about major changes in their business and markets has become crucial for organizations. They need to reconsider their strategies and operating plans. Only companies that can anticipate emerging trends and opportunities, refocus business strategy and vision, and align resources to maximize performance can effectively deal with the adversities of economic downturn and gain competitive advantage. BI and Performance Management brings business sensibility with enhanced visibility and insights, by delivering accurate and latest information to the right people for faster, improved, strategic and tactical decision making. Companies have increasingly starting realizing the importance of timely performance information to improve results, which will further make way for the rising demand for BI and Corporate Performance Management Solutions.</p>
<p style="text-align:justify;"><strong>Business Intelligence via Software As A Service (SaaS) </strong></p>
<p style="text-align:justify;">It is being anticipated that in the coming years a number of organizations will have an industry-specific analytic application delivered via software as a service (SaaS) as a standard component of their BI portfolio. Information aggregators will bank on SaaS to deliver domain-specific analytic applications, which are made from industry data they assemble, and bring the balance of power in the BI platform market in their favor. Organizations will share their data with only those aggregators that can assure security as well as confidentiality. Thus, countless information aggregators offering SaaS analytic applications might appear; however, a virtual monopoly is expected to remain within each vertical niche owing to the high barricade that blocks the entry for others.</p>
<p><img class="alignnone" src="http://www.pinaldave.com/bimg/bi1.jpg" alt="" width="500" height="299" /></p>
<p style="text-align:justify;"><strong>Business Intelligence and Social Software</strong></p>
<p style="text-align:justify;">Collaborative decision making will soon become the norm, which amalgamates social software with BI Platform capabilities. With social software users can tag assumptions made in the decision-making process to the BI framework, which significantly enhances the business value of BI as it ties all the good. Take for instance, in order to decide how much to invest in marketing a new product, users can tag their assumptions about the future sales of that product to a key performance indicator (KPI) that measures product sales. Whenever the KPI surpasses a threshold the BI platform would send alerts to the user to inform the decision makers about assumptions that no longer hold true.</p>
<p style="text-align:justify;">With the advent of social software it has become easier to utilize the upsurge of interest in informal collaboration. As an alternative to the advancing of the usual top-down decision-making initiative, social software will be employed to collaborate and make decisions.</p>
<p style="text-align:justify;"><strong>Business Intelligence Across All Sectors </strong></p>
<p style="text-align:justify;">BI is on its way to become an integral component of every type and size of organization across all sectors, including Real estate, IT, mobile devices, governmental agencies, scientific and engineering communities and R&amp;D labs, banking and insurance, to name a few. BI can effectively deal with industry-specific constraints, operations and objectives thereby helping organizations better understand their customers, optimize their operations, minimize risk, manage revenue, and ultimately improve their results. More importantly, it is expected that in a couple of years BI will soon replace the gut-feel management with real data-based decision-making.</p>
<p style="text-align:justify;"><strong>Business Intelligence For Real-Time Data</strong></p>
<p style="text-align:justify;">Today, consumers are demanding faster and improved services from businesses. As it has become imperative for companies to pay attention to consumer satisfaction in order to stay competitive they are depending even more on BI. They now demand near real-time analysis for intelligent decisions for business success. The rising demand for near-real-time data analysis is making way for a new framework for business intelligence. BI 2.0 is the recently-coined term to describe the acquisition, provision and analysis of real- time data, which was earlier lacking in BI. BI 2.0 is a part of the constantly developing business intelligence industry and indicates the next step for BI.</p>
<p style="text-align:justify;">In near future, companies will switch from the traditional model of making business adjustments on a quarterly basis to business intelligence and performance management tools to make real-time shifts in strategy to respond to changes in the marketplace.</p>
<p style="text-align:justify;"><strong>Over the coming years, business intelligence will undergo transformation that will have a broad and lasting impact. It will revolutionize the way that we think about business and the way business decisions are made. It’s only when thoughtful analysis supersedes gut feeling and conventional perception, we will enter the next level of business intelligence that will empower businesses with the capacity to reason, prepare, forecast, resolve issues and innovate.</strong></p>
<p style="text-align:justify;">Reference : <strong>Nupur Dave</strong> <strong>(<a href="http://blog.sqlauthority.com" target="_blank">http://blog.sqlauthority.com</a>)</strong></p>
Posted in Business Intelligence, Data Warehousing, Database, DBA, Readers Contribution, SQL, SQL Authority, SQL Query, 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/5013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5013/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5013&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/05/08/sqlauthority-news-future-of-business-intelligence-and-databases-article-by-nupur-dave/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/bi2.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/bi1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Add or Remove Identity Property on Column</title>
		<link>http://blog.sqlauthority.com/2009/05/03/sql-server-add-or-remove-identity-property-on-column/</link>
		<comments>http://blog.sqlauthority.com/2009/05/03/sql-server-add-or-remove-identity-property-on-column/#comments</comments>
		<pubDate>Sun, 03 May 2009 01:30:20 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></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>
		<category><![CDATA[Identity]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4872</guid>
		<description><![CDATA[This article contribution from one of my favorite SQL Expert Imran Mohammed. He is one man who has lots of ideas and helps people from all over the world with passion using this community as platform. His constant zeal to learn more about SQL Server keeps him engaging him to do new SQL Server related [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4872&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This article contribution from one of my favorite SQL Expert <strong>Imran Mohammed</strong>. He is one man who has lots of ideas and helps people from all over the world with passion using this community as platform. His constant zeal to learn more about SQL Server keeps him engaging him to do new SQL Server related activity every time.</p>
<p style="text-align:justify;"><em><span style="text-decoration:underline;">1. Adding Identity Property to an existing column in a table. </span></em></p>
<p style="text-align:justify;">How difficult is it to add an Identity property to an existing column in a table? Is there any T-SQL that can perform this action?</p>
<p style="text-align:justify;">For most, the answer to the above two questions is an absolute NO! There is no straightforward T-SQL like ALTER TABLE&#8230; or MODIFY COLUMN to add an Identity Property to an existing column in a table.</p>
<p style="text-align:justify;">However, there is an easy way to accomplish this action. It can be done through SSMS.</p>
<p style="text-align:justify;">Are you finding my answer difficult to believe? Let me explain.</p>
<p style="text-align:justify;">Let&#8217;s first see what SSMS does in backend when you add Identity property on an existing column in any table.</p>
<p style="text-align:justify;">Now, let&#8217;s create an example table for better understanding.</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/im1.jpg" alt="" width="351" height="201" /></p>
<p style="text-align:justify;">This table is vacant, with no records, as you can see in the following screenshot.</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/im2.jpg" alt="" width="350" height="247" /></p>
<p style="text-align:justify;">Take a look at the design of this table in SSMS.</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/im3.jpg" alt="" width="442" height="576" /></p>
<p style="text-align:justify;">Now let us make eid, an Identity column.</p>
<p style="text-align:justify;">This is very easy.  All you have to do is just select <strong>Yes</strong> from the drop down list and you are done!</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/im4.jpg" alt="" width="479" height="609" /></p>
<p style="text-align:justify;">But before moving further let&#8217;s see what T-SQL SQL Server is using to make this change.</p>
<p style="text-align:justify;">You will notice that T-SQL is used by SQL Server to make this change.</p>
<p style="text-align:justify;">After you make the change for Identity property from No to Yes, on top in tools box, you will see <strong>Generate Change Script</strong>. This is the T-SQL Script that SQL Server will use to make this change.</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/im5.jpg" alt="" width="481" height="613" /></p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/im6.jpg" alt="" width="456" height="366" /></p>
<p style="text-align:justify;">Unfortunately, I cannot expand this dialogue box further to show you the complete script, so I have copied this script below.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/</span><span style="color:blue;"><br />
BEGIN </span><span style="color:black;">TRANSACTION<br />
</span></code><code style="font-size:12px;"><span style="color:blue;">SET</span></code><code style="font-size:12px;"><span style="color:black;"> QUOTED_IDENTIFIER </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">ARITHABORT </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">NUMERIC_ROUNDABORT </span><span style="color:blue;">OFF<br />
SET </span><span style="color:black;">CONCAT_NULL_YIELDS_NULL </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">ANSI_NULLS </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">ANSI_PADDING </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">ANSI_WARNINGS </span><span style="color:blue;">ON<br />
COMMIT<br />
BEGIN TRANSACTION<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">dbo.Tmp_example1<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">eid </span><span style="color:blue;">INT </span><span style="color:gray;">NOT NULL </span><span style="color:#434343;">IDENTITY </span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">)<br />
) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO<br />
</span><span style="color:blue;">SET IDENTITY_INSERT </span><span style="color:black;">dbo.Tmp_example1 </span><span style="color:blue;">ON<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">IF </span><span style="color:gray;">EXISTS(</span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">dbo.example1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">EXEC</span><span style="color:gray;">(</span><span style="color:red;">'INSERT INTO dbo.Tmp_example1 (eid)<br />
SELECT eid FROM dbo.example1 WITH (HOLDLOCK TABLOCKX)'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SET IDENTITY_INSERT </span><span style="color:black;">dbo.Tmp_example1 </span><span style="color:blue;">OFF<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">dbo.example1<br />
GO<br />
</span><span style="color:blue;">EXECUTE </span><span style="color:darkred;">sp_rename </span><span style="color:red;">N'dbo.Tmp_example1'</span><span style="color:gray;">, </span><span style="color:red;">N'example1'</span><span style="color:gray;">, </span><span style="color:red;">'OBJECT'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">COMMIT</span></code>
</p>
<p style="text-align:justify;">Let us understand above code in simple words:</p>
<p style="text-align:justify;"><em>Begin Transaction<br />
Step 1: Create similar table structure as example1, say Tmp_Example1 with Identity Column.<br />
Step 2: Set IDENTITY_INSERT ON on new table just created.Step 3: Insert all values from example1 to Tmp_Example1<br />
Step 4: Set IDENTITY_INSERT OFF on Tmp_Example..<br />
Step 5: Drop example1 (What is going on&#8230; dropping our original table???)<br />
Step 6: Rename Tmp_Example1 to Example1.<br />
Commit Transaction</em>
</p>
<p style="text-align:justify;">What if you have millions and millions of records in your table?</p>
<p style="text-align:justify;">Imagine how much time it would take to copy an entire table?</p>
<p style="text-align:justify;">Just to make a column Identity do you really need to go through all these and take so much pain?</p>
<p style="text-align:justify;">Certainly not!</p>
<p style="text-align:justify;">Same is the case when you want to remove Identity column property from a column.</p>
<p style="text-align:justify;"><em><span style="text-decoration:underline;">2. Removing Identity Property from an existing column in a table. </span></em></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/<br />
</span></code><code style="font-size:12px;"><span style="color:blue;">BEGIN </span><span style="color:black;">TRANSACTION<br />
</span></code><code style="font-size:12px;"><span style="color:blue;">SET</span></code><code style="font-size:12px;"><span style="color:black;"> QUOTED_IDENTIFIER </span><span style="color:blue;">ON</span></code><code style="font-size:12px;"><span style="color:blue;"><br />
SET </span><span style="color:black;">ARITHABORT </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">NUMERIC_ROUNDABORT </span><span style="color:blue;">OFF<br />
SET </span><span style="color:black;">CONCAT_NULL_YIELDS_NULL </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">ANSI_NULLS </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">ANSI_PADDING </span><span style="color:blue;">ON<br />
SET </span><span style="color:black;">ANSI_WARNINGS </span><span style="color:blue;">ON<br />
COMMIT<br />
BEGIN TRANSACTION<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">dbo.Tmp_example1<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">eid </span><span style="color:blue;">INT </span><span style="color:gray;">NOT NULL<br />
) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO<br />
</span><span style="color:blue;">IF </span><span style="color:gray;">EXISTS(</span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">dbo.example1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">EXEC</span><span style="color:gray;">(</span><span style="color:red;">'INSERT INTO dbo.Tmp_example1 (eid)<br />
SELECT eid FROM dbo.example1 WITH (HOLDLOCK TABLOCKX)'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">dbo.example1<br />
GO<br />
</span><span style="color:blue;">EXECUTE </span><span style="color:darkred;">sp_rename </span><span style="color:red;">N'dbo.Tmp_example1'</span><span style="color:gray;">, </span><span style="color:red;">N'example1'</span><span style="color:gray;">, </span><span style="color:red;">'OBJECT'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">COMMIT</span></code></p>
<p style="text-align:justify;">Once again, I would like to congratulate <strong>Imran Mohammed </strong>for this wonderful article.</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>
Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology Tagged: Identity <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4872/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4872/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4872/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4872/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4872/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4872/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4872/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4872/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4872/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4872/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4872&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/05/03/sql-server-add-or-remove-identity-property-on-column/feed/</wfw:commentRss>
		<slash:comments>8</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/im1.jpg" medium="image" />

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

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

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

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

		<media:content url="http://www.pinaldave.com/bimg/im6.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Leading Zero to Number</title>
		<link>http://blog.sqlauthority.com/2009/04/24/sql-server-leading-zero-to-number/</link>
		<comments>http://blog.sqlauthority.com/2009/04/24/sql-server-leading-zero-to-number/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 02:00:50 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></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/?p=4520</guid>
		<description><![CDATA[I have received few emails asking how to prefix any number with zero. I have previously written two articles for the same subject. Please refer to my previous articles.
SQL SERVER &#8211; Pad Ride Side of Number with 0 &#8211; Fixed Width Number Display
SQL SERVER &#8211; UDF &#8211; Pad Ride Side of Number with 0 &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4520&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I have received few emails asking how to prefix any number with zero. I have previously written two articles for the same subject. Please refer to my previous articles.</p>
<p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/03/10/sql-server-pad-ride-side-of-number-with-0-fixed-width-number-display/" target="_blank">SQL SERVER &#8211; Pad Ride Side of Number with 0 &#8211; Fixed Width Number Display</a></strong></p>
<p><strong><a href="http://blog.sqlauthority.com/2009/03/16/sql-server-udf-pad-ride-side-of-number-with-0-fixed-width-number-display/" target="_blank">SQL SERVER &#8211; UDF &#8211; Pad Ride Side of Number with 0 &#8211; Fixed Width Number Display</a></strong></p>
<p style="text-align:justify;">Let me know if you are aware of any other method.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4520/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4520&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/04/24/sql-server-leading-zero-to-number/feed/</wfw:commentRss>
		<slash:comments>0</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; Poll Result &#8211; What is Your Favorite Database?</title>
		<link>http://blog.sqlauthority.com/2009/04/15/sql-server-poll-result-what-is-your-favorite-database/</link>
		<comments>http://blog.sqlauthority.com/2009/04/15/sql-server-poll-result-what-is-your-favorite-database/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 01:30:24 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Poll]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></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://blog.sqlauthority.com/?p=4323</guid>
		<description><![CDATA[I previously posted a Poll about What is Your Favorite Database?
I got great response from users. In fact, I received some of the best poll-related comments on this blog  and they are worth reading.
Let us check the result first. Here are the votes I received on different database. Total votes received are 1,697.
SQL Server &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4323&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I previously posted a Poll about <strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/" target="_blank">What is Your Favorite Database?</a></strong></p>
<p style="text-align:justify;">I got great response from users. In fact, I received some of the best poll-related comments on this blog  and they are worth reading.</p>
<p style="text-align:justify;">Let us check the result first. Here are the votes I received on different database. Total votes received are <strong>1,697</strong>.</p>
<p style="text-align:justify;"><strong>SQL Serve</strong>r &#8211; 1,121 &#8211; 64%</p>
<p style="text-align:justify;"><strong>Oracle</strong> &#8211; 432 &#8211; 25%</p>
<p style="text-align:justify;"><strong>MySQL</strong> &#8211; 144 &#8211; 8%</p>
<p style="text-align:justify;"><strong>Other</strong> &#8211; 64 &#8211; 4%</p>
<p style="text-align:justify;">SQL Server is a clear winner with  1,121 votes, which is an astounding 64% of the total votes. As a matter of fact, it is not startling to see SQL Server  emerge as a winner as this blog is primarily focused on SQL Server, and  on top of that SQL Server is the most popular language.</p>
<p style="text-align:justify;">Lotus Notes/Lotus Domino (total 12 votes) and PostegreSQL (total 12 votes) are the top two DBMS in other section.</p>
<p style="text-align:justify;">Let us have a look at the result in the following image. Here,  I have included all the DBMS who received more than 1 vote.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/pollresult.jpg" alt="" width="703" height="615" /></p>
<p style="text-align:justify;">Now I would like to announce the winner who gave the best comment.  And the winner  is <strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/#comment-48853" target="_blank">Brian Tkatch</a></strong>. I could not stop laughing after reading his comment. He is dear friend of mine and a SQL Expert who has  actively participated several times on this blog earlier.  <strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/#comment-47436" target="_blank">Imran Mohammed</a></strong> and <strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/#comment-47525" target="_blank">phat shantz</a></strong> also came up with interesting comments. I thoroughly enjoyed reading their comments as they discussed unknown details about other database. The comment from <strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/#comment-47362" target="_blank">Jeff </a></strong> further led to some good discussion on the topic. I have not edited any of their comments and have published their original version.</p>
<p style="text-align:justify;"><strong>Comment of </strong><strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/#comment-48853" target="_blank">Brian Tkatch</a> :</strong></p>
<p style="padding-left:30px;text-align:justify;">I prefer the DB that is best suited for the job. If there job can use any, i prefer Oracle because it makes the most sense to me.</p>
<p style="padding-left:30px;text-align:justify;">I’ve use a few RDBMs, but for short periods, like a year or two. I have very particular tastes, and as such am heavily biased, so IMNSHO:</p>
<p style="padding-left:30px;text-align:justify;">SQL Server implements what programmers want, and then bends to the way things should be where it doesn’t add too much inconvenience.</p>
<p style="padding-left:30px;text-align:justify;">Pros: Integrated, easy to manage, secure, supported, low cost, convenient in most cases, Pinal Dave</p>
<p style="text-align:justify;">Cons: inconvenient in some cases (SET NOCOUNT ON et al, non-ANSI join-syntax is deprecated, and others) bar set too low for DBAs (allowing much idiocy), no robust command line tool</p>
<p style="padding-left:30px;text-align:justify;">Oracle implements things the way they should be done, and then bends to the programmer where it is helpful but does not break any ideas.</p>
<p style="padding-left:30px;text-align:justify;">Pros: Robust, secure, supported, fast, long history</p>
<p style="text-align:justify;">Cons: Very expensive, inconvenient in some cases</p>
<p style="padding-left:30px;text-align:justify;">MySQL isn’t a database. It’s free and fast for lightweight applications, but lacks security and robustness of a real database. I’d use it where speed and cost are factors, but not security or data retention.</p>
<p style="padding-left:30px;text-align:justify;">Pros: Fast, free</p>
<p style="text-align:justify;">Cons: Not secure, error messages rarely help, not robust, no reliable data retention, slow on complex queries with large data sets.</p>
<p style="padding-left:30px;text-align:justify;">Others include:</p>
<p style="padding-left:30px;text-align:justify;">DB2 implements whatever it can, trying to make everybody happy, supporting the popular features of both SQL Server and Oracle. I would use it where being an IBM shop made sense. Otherwise, SQL Server or Oracle could easily do the same job.</p>
<p style="padding-left:30px;text-align:justify;">Pros: Supports everything. Cheap. Supported by IBM.</p>
<p style="text-align:justify;">Cons: Easy to crash (i crashed it, that is the server, 4 different times by running regular queries), lack of distinctness</p>
<p style="padding-left:30px;text-align:justify;">PostgreSQL is similar to Oracle, but free. I’d use it anywhere other people would use MySQL but want a database instead, or where commercial support is a must.</p>
<p style="padding-left:30px;text-align:justify;">Pros: Fast, free, secure</p>
<p style="text-align:justify;">Cons: Relatively small community supporting it</p>
<p style="padding-left:30px;text-align:justify;">Access is a RAD for small applications.</p>
<p style="padding-left:30px;text-align:justify;">Pros: Cheap, integrated, RAD</p>
<p style="text-align:justify;">Cons: Single user, not for large applications.</p>
<p style="padding-left:30px;text-align:justify;">One word:</p>
<p style="padding-left:30px;text-align:justify;"><em><strong>SQL Server &#8211; Easy</strong></em></p>
<p style="text-align:justify;"><em><strong>Oracle &#8211; Robust</strong></em></p>
<p style="text-align:justify;"><em><strong>MySQL &#8211; Fake</strong></em></p>
<p style="text-align:justify;"><em><strong>DB2 &#8211; Contender</strong></em></p>
<p style="text-align:justify;"><em><strong>PostgreSQL &#8211; Free</strong></em></p>
<p style="text-align:justify;"><em><strong>Access &#8211; Small</strong></em></p>
<p style="padding-left:30px;text-align:justify;">Thank you for reading. I think i got it out of my system now. :)</p>
<p style="text-align:justify;"><strong>Comment of </strong><strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/#comment-47436" target="_blank">Imran Mohammed</a> :</strong></p>
<p style="padding-left:30px;text-align:justify;">BEST RDBMS in Market :</p>
<p style="padding-left:30px;text-align:justify;">SQL Server</p>
<p style="padding-left:30px;text-align:justify;">Few reasons:</p>
<p style="padding-left:30px;text-align:justify;">1. Costs Less.</p>
<p style="text-align:justify;">2. Extra Security.</p>
<p style="text-align:justify;">3. Extra features</p>
<p style="text-align:justify;">4. Comes with many free tools.</p>
<p style="text-align:justify;">5. Have capabilities to handle VLDB (UPSS &#8211; 18 TB, Myspace uses SQL Server)</p>
<p style="text-align:justify;">6. Comparatively easy to handle/Interfaces.</p>
<p style="padding-left:30px;text-align:justify;">List goes on and on….</p>
<p style="padding-left:30px;text-align:justify;"><strong><em>More Important… I am getting monthly pay cheques because I am SQL Server DBA. :)</em></strong></p>
<p style="text-align:justify;"><strong>Comment of </strong><strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/#comment-47525" target="_blank">phat shantz</a> :</strong></p>
<p style="padding-left:30px;text-align:justify;">For years I built standalone business applications using c-Tree, a high-performance, cross-platform database from Faircom that could be implemented with native or server based access.</p>
<p style="padding-left:30px;text-align:justify;">I still think c-Tree is the best database in the universe, although the downside is the limited acceptance and limited developer resources.</p>
<p style="padding-left:30px;text-align:justify;">For the past few years, all my clients have used SQL Server.</p>
<p style="padding-left:30px;text-align:justify;">Like all things Microsoft, SQL Server is a “good-enough” solution, so using and implementing it is tolerable. Since it plays well with MS office and MS builds all its business-centric products around it, it becomes the de-facto standard.</p>
<p style="padding-left:30px;text-align:justify;">Compromise is not always the best course, but when dealing with jumpy executives and poorly-trained IT, sometimes the best you can do is compromise.</p>
<p style="padding-left:30px;text-align:justify;">Even for some of the grandest projects, Oracle has usually been overkill. It’s expensive, a hog, slow (in my experience — and don’t blame me, it was always administered by a “professional” Oracle admin), but will handle 500,000 transactions in a gulp. I have seen one implementation of an Oracle database that actually needed that kind of horsepower.</p>
<p style="padding-left:30px;text-align:justify;">Sybase and MySQL need no comments. Their fanbois are poised out there, ready to tout their superiority and flame anyone who disagrees.</p>
<p style="padding-left:30px;text-align:justify;">Like one of your commenters stated, the question should be “what’s your favorite database for X type of project?”</p>
<p style="padding-left:30px;text-align:justify;">If the environment is Microsoft and the platform is business and the clients and staff are untrained and largely uninformed, the answer is always SQL Server.</p>
<p style="padding-left:30px;text-align:justify;">Still, I would never undertake a project using SQL Server without one of the best ORM/EF products available. Microsoft’s LINQ and EF are both less palatable as database access layers than are the visual components that come in Visual Studio tolerable as win or web-form components. (While most of what MS delivers is “good enough,” I think MS delivered LINQ and EF so they could claim they provide something. As they dissatisfied girlfriend says of the gift from an unwanted suitor, “you shouldn’t have.”</p>
<p style="padding-left:30px;text-align:justify;">Just as I would never deliver a product using the world’s ugliest visual components (the VS toolbox), I would never use SQL Server without a quality (and pricey) ORM.</p>
<p style="padding-left:30px;text-align:justify;">Even with all it’s drawbacks, sometimes the answer is SQL Server even if the staff and clients are very skilled and knowledgeable. I can think of some cases where it is the best answer, but the meta-requirements have to go far beyond capacity, speed, platform, or tools.</p>
<p style="padding-left:30px;text-align:justify;">I guess there will always be a few “BetaMax” databases out there that are far superior in performance and capability to SQL Server. But the Redmond Marketing Horde has long conquered the battleground and there is little hope of the best rising above the most popular.</p>
<p style="text-align:justify;"><strong>Comment of </strong><strong><a href="http://blog.sqlauthority.com/2009/02/25/the-poll-what-is-your-favorite-database/#comment-47362" target="_blank">Jeff</a> :</strong></p>
<p style="padding-left:30px;text-align:justify;">I’m not sure thats a fair question to ask. There are TONS of databases out there both free and commerical. The real question is always whats you’re favorite database for X.</p>
<p style="padding-left:30px;text-align:justify;">For a ‘Enterprise’ DB, I like Sql server. It has a low barrier to entry, good tools, reasonable price point etc etc. I like PL/SQL as a stored proc language better than t-sql, but I find the learning curve for new developers to be higher on Oracle.</p>
<p style="padding-left:30px;text-align:justify;">MySQL’s licensing terms, specifically the GPL’ed ADO.Net provider, personally make it a ‘meh’ option in the open source / free category. If I had to pick an enterprise database for linux shops I’d go with Postgres or Firebird first. MySQL’s ability to have differing disk formats is a really great feature. However the disk formats that it ships with are in my book un-compelling. Postgres and Firebird both have much better concurrency models. They both have much better procedural languages. They dont ‘blackmail’ me into buying support by GPLing a component that every other vendor on the planet licenses under the LGPL and then offering a binary-only support contract.</p>
<p style="padding-left:30px;text-align:justify;">One database I find myself using a lot is SQLite. It’s a very very simple database. It’s serverless, locking is coordinated through the database file. The resource requirements are low enough for use in embeded systems. The great part about it is the zero-config aspect of it All you need to do is link in the library and point it at the db file. This is great for stuff you’d never think of using a database for otherwise. If I’m writing an application that needs data files, I can make them a database. I can use it as a light-weight db for unit testing. For webapps that expect an unzip and go deployment it’s a wonderful option. I can have a real db that simply lives on a file in the app.</p>
<p style="text-align:justify;"><strong>I am really thankful to all of my blog readers and every person who participated in Poll. As requested by many readers, I will have new poll very soon. </strong></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)<br />
</strong></p>
Posted in Database, Pinal Dave, Poll, Readers Contribution, SQL, SQL Authority, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4323/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4323&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/04/15/sql-server-poll-result-what-is-your-favorite-database/feed/</wfw:commentRss>
		<slash:comments>2</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/pollresult.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Logical Query Processing Phases &#8211; Order of Statement Execution</title>
		<link>http://blog.sqlauthority.com/2009/04/06/sql-server-logical-query-processing-phases-order-of-statement-execution/</link>
		<comments>http://blog.sqlauthority.com/2009/04/06/sql-server-logical-query-processing-phases-order-of-statement-execution/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 01:30:20 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Logical Query Processing Phases]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4218</guid>
		<description><![CDATA[Download Logical Query Processing Poster
Of late, I penned down an article &#8211; SQL SERVER &#8211; Interesting Observation of ON Clause on LEFT JOIN &#8211; How ON Clause Effects Resultset in LEFT JOIN &#8211; which received a very intriguing comment  from one of my regular blog readers Craig. According to him this phenomenon happens due [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4218&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><strong><a href="http://www.pinaldave.com/best-sql-server-download.cfm?Download=Logical-Query-Processing-Poster" target="_blank"><strong>Download Logical Query Processing Poster</strong></a></strong></p>
<p style="text-align:justify;">Of late, I penned down an article &#8211; <strong><a href="http://blog.sqlauthority.com/2009/03/15/sql-server-interesting-observation-of-on-clause-on-left-join-how-on-clause-effects-resultset-in-left-join/" target="_blank">SQL SERVER &#8211; Interesting Observation of ON Clause on LEFT JOIN &#8211; How ON Clause Effects Resultset in LEFT JOIN</a></strong> &#8211; which received a very intriguing <a href="http://blog.sqlauthority.com/2009/03/15/sql-server-interesting-observation-of-on-clause-on-left-join-how-on-clause-effects-resultset-in-left-join/#comment-49834" target="_blank">comment </a> from one of my regular blog readers <strong>Craig</strong>. According to him this phenomenon happens due to Logical Query Processing. His comment instigated a question in my mind. I have put forth this question to all my readers at the end of the article. Let me first give you an introduction to Logical Query Processing Phase.</p>
<p style="text-align:justify;">What actually sets SQL Server apart from other programming languages is the way SQL Server processes its code. Generally, most programming languages process statement from top to bottom. By contrast, SQL Server processes them in a unique order which is known as Logical Query Processing Phase. These phases generate a series of virtual tables with each virtual table feeding into the next phase (virtual tables not viewable). These phases and their orders are given as follows:</p>
<p style="text-align:justify;">1. FROM<br />
2. ON<br />
3. OUTER<br />
4. WHERE<br />
5. GROUP BY<br />
6. CUBE | ROLLUP<br />
7. HAVING<br />
8. SELECT<br />
9. DISTINCT<br />
10 ORDER BY<br />
11. TOP</p>
<p style="text-align:justify;">As OUTER join is applied subsequent to ON clause, all rows eliminated by the ON clause will still be included by the OUTER join as described in the article <strong><a href="http://blog.sqlauthority.com/2009/03/15/sql-server-interesting-observation-of-on-clause-on-left-join-how-on-clause-effects-resultset-in-left-join/" target="_blank">SQL SERVER &#8211; Interesting Observation of ON Clause on LEFT JOIN &#8211; How ON Clause Effects Resultset in LEFT JOIN</a>.</strong></p>
<p style="text-align:justify;">However, I am perplexed about the last two, ORDER BY and TOP. According to some people TOP comes first in logical query processing phase while others suggest that ORDER BY comes first. Now, here I’ve laid down my questions for you all to think about:</p>
<p style="text-align:justify;">1) What is the correct answer for order query processing phase &#8211; ORDER BY or TOP?<br />
2) How can we create an example to verify query processing phase for ORDER BY and TOP?</p>
<p style="text-align:justify;">I will soon publish the answers I receive to the above questions on this blog, with due credit given to my readers.</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 Database, Pinal Dave, Readers Contribution, Readers Question, Software Development, SQL, SQL Authority, SQL Joins, SQL Query, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology Tagged: Logical Query Processing Phases <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4218/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4218&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/04/06/sql-server-logical-query-processing-phases-order-of-statement-execution/feed/</wfw:commentRss>
		<slash:comments>22</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; Automated Index Defragmentation Script</title>
		<link>http://blog.sqlauthority.com/2009/04/04/sql-server-automated-index-defragmentation-script/</link>
		<comments>http://blog.sqlauthority.com/2009/04/04/sql-server-automated-index-defragmentation-script/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 01:30:57 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></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 Website Review]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4232</guid>
		<description><![CDATA[Index Defragmentation is one of the key processes to significantly improve performance of any database. Index fragments occur when any transaction takes place in database table.  Fragmentation typically happens owing to insert, update and delete transactions. Having said that, fragmented data can produce unnecessary reads thereby reducing performance of heavy fragmented tables.
I have often been [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4232&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Index Defragmentation is one of the key processes to significantly improve performance of any database. Index fragments occur when any transaction takes place in database table.  Fragmentation typically happens owing to insert, update and delete transactions. Having said that, fragmented data can produce unnecessary reads thereby reducing performance of heavy fragmented tables.</p>
<p style="text-align:justify;">I have often been asked to share my personal Index Defragmentation Script. Well, I use Automated Index Defragmentation Script created by my friend &#8211; a SQL Expert &#8211; <strong><a href="http://sqlfool.com/about/" target="_blank">Michelle Ufford</a></strong> (a.k.a <strong>SQLFool</strong>). Michelle is a SQL Server Developer, DBA, a humble blogger, and an absolute geek! She is also the President of Eastern Iowa PASS Chapter, known as the I380 Corridor Professional Association of SQL Server. Currently, she is working with large, high volume, high performance SQL Server databases at GoDaddy.com. Her nickname might be SQLFool but honestly speaking, she is one of the best Gurus of SQL.  You can read her  <strong><a href="http://sqlfool.com/" target="_blank">blog </a></strong>here.</p>
<p style="text-align:justify;">Michelle has written an excellent article about Automated Index Defragmentation Script. I recommend this wonderful write-up to all those database developers who are searching for a good solution to improve database performance. Read her article <strong><a href="http://sqlfool.com/2009/03/automated-index-defrag-script/" target="_blank">Automated Index Defragmentation Script</a></strong> to equip yourself with better understanding on how to improve database performance.</p>
<p style="text-align:justify;">Here, I would to mention an interesting question taken from the above-mentioned article, which will clearly show how powerful this Automated Index Defragmentation Script is.</p>
<p style="text-align:justify;"><strong>How long will this Automated Index Defragmentation Script  take to run?</strong><br />
Well, it depends. I don’t necessarily recommend running it without specifying a database; at least, not unmonitored. You *can* do that, but it could take a while. For example, to run sys.dm_db_index_physical_stats for all databases and tables, totaling 2TB, took me 4.5 hours; that doesn’t even count the actual defrags.
</p>
<p style="text-align:justify;">You can <strong><a href="http://sqlfool.com/scripts/dba_indexDefrag_sp.txt" target="_blank">download the script</a></strong> from here.</p>
<p style="text-align:justify;">Please feel free to contact Michelle or me if you have any questions and doubts regarding this script.</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="text-align:justify;">
Posted in Best Practices, Database, Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLAuthority Website Review, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4232/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4232&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/04/04/sql-server-automated-index-defragmentation-script/feed/</wfw:commentRss>
		<slash:comments>10</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; Activity Monitor is Empty &#8211; Fix Activity Monitor for All Users</title>
		<link>http://blog.sqlauthority.com/2009/03/22/sql-server-2008-activity-monitor-is-empty-fix-activity-monitor-for-all-users/</link>
		<comments>http://blog.sqlauthority.com/2009/03/22/sql-server-2008-activity-monitor-is-empty-fix-activity-monitor-for-all-users/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 01:30:17 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Error Messages]]></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 Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL Activity Monitor]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=3862</guid>
		<description><![CDATA[This article is outcome of the technical discussion of activity monitor and its behavior with my friend and SQL Expert Tejas Shah. Tejas told me that he does not like to re-write content from MSDN but rather prefer to write real life scenarios, as that prepares him to become better SQL Expert. While discussing about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=3862&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This article is outcome of the technical discussion of activity monitor and its behavior with my friend and SQL Expert <strong><a href="http://tejasnshah.wordpress.com/" target="_blank">Tejas Shah</a></strong>. Tejas told me that he does not like to re-write content from MSDN but rather prefer to write real life scenarios, as that prepares him to become better SQL Expert. While discussing about Activity Monitor he informed that activity monitor throws an error when there is permissions issue. He has even blogged about <a href="http://tejasnshah.wordpress.com/2009/03/22/sql-server-unable-to-launch-activity-monitor-how-to-give-view-server-state-permissions-to-launch-activity-monitor/" target="_blank">how to give permissions to user to launch activity monitor</a> on his blog . Tejas asked me to write on the same subject for SQL Server 2008. Here is the article covering the discussion I had with Tejas.</p>
<p style="text-align:justify;">I have user called &#8216;ActivityUser&#8217; when turned on Activity Monitor (while logging in with user ActivityUser&#8217;) it does not have show anything in Activity Monitor.</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/bimg/avmon/av1.jpg"><img class="alignnone" src="http://www.pinaldave.com/bimg/avmon/av1_s.jpg" alt="" width="500" height="263" /></a></p>
<p style="text-align:justify;">The issue here is permissions issue. If user ActivityUser is given all the necessary permission it will start showing up data in Activity Monitor. Activity Monitor is new tool in SQL Server which displays activity in five sections. 1) Overview, 2) Processes, 3) Resources Waits, 4) Data File I/O, 5) Recent Expensive Queries. It is one of the new and very useful tool introduced by SQL Server.</p>
<p style="text-align:justify;">Activity Monitor captures all the information at server level. For the same reason we need to give <em><strong>&#8220;View Server State&#8221;</strong></em> permission to user name to view data of Activity Monitor.We can give permission either using T-SQL or using SSMS.</p>
<p style="text-align:justify;">T-SQL to give permission to user to view Activity Monitor:</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/avmon/av2.jpg" alt="" width="429" height="232" /></p>
<p style="text-align:justify;">SSMS to give permission to user to view Activity Monitor:</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/avmon/av3.jpg" alt="" width="500" height="449" /></p>
<p style="text-align:justify;">Once permissions is given to user, it displays the data in Activity Monitor. Click on images to enlarge the images.</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/bimg/avmon/av4.jpg"><img class="alignnone" src="http://www.pinaldave.com/bimg/avmon/av4_s.jpg" alt="" width="500" height="281" /></a></p>
<p style="text-align:justify;">Additionally, note that if you are user belonging to sysadmin role, you can always see all the data in Activity Monitor without additional permissions.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.sqlauthority.com</a>)</strong></p>
Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Error Messages, SQL Performance, SQL Query, SQL Scripts, SQL Security, SQL Server, SQL Tips and Tricks, T SQL, Technology Tagged: SQL Activity Monitor <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/3862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/3862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/3862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/3862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/3862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/3862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/3862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/3862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/3862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/3862/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=3862&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/03/22/sql-server-2008-activity-monitor-is-empty-fix-activity-monitor-for-all-users/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>

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

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

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

		<media:content url="http://www.pinaldave.com/bimg/avmon/av4_s.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Practical SQL Server XML: Part One &#8211; Query Plan Cache and Cost of Operations in the Cache</title>
		<link>http://blog.sqlauthority.com/2009/03/17/sql-server-practical-sql-server-xml-part-one-query-plan-cache-and-cost-of-operations-in-the-cache/</link>
		<comments>http://blog.sqlauthority.com/2009/03/17/sql-server-practical-sql-server-xml-part-one-query-plan-cache-and-cost-of-operations-in-the-cache/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 01:30:32 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></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[SQL Utility]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL XML]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=3747</guid>
		<description><![CDATA[I am very fortunate that I have friends like Michael Coles. Michael Coles is SQL Server and XML expert and have written many books on SQL Server as well XML. He has previously written book which I have reviewed on this blog SQLAuthority News &#8211; Book Review &#8211; Pro T-SQL 2005 Programmer’s Guide (Paperback). I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=3747&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I am very fortunate that I have friends like Michael Coles. Michael Coles is SQL Server and XML expert and have written many books on SQL Server as well XML. He has previously written book which I have reviewed on this blog <strong><a href="http://blog.sqlauthority.com/2007/09/15/sqlauthority-news-book-review-pro-t-sql-2005-programmers-guide-paperback/" target="_blank">SQLAuthority News &#8211; Book Review &#8211; Pro T-SQL 2005 Programmer’s Guide (Paperback)</a></strong>. I am currently reading his latest book <a href="http://www.amazon.com/dp/1590599837" target="_blank">Pro SQL Server 2008 XML (Hardcover)</a> which can be found on amazon. I will be writing review of the book once I am done reading it.</p>
<p style="text-align:justify;">Michael Coles and I met last at Microsoft MVP Summit 2009 at Seattle and I come to know he very much young and dynamic person who is friend of everybody. His knowledge of SQL Server is exception and I had requested him to write one practical demonstration of XML and he took up this challenge very well and the out come of that challenge is I am going to publish in this blog as it is.</p>
<p style="text-align:justify;">
<div class="wp-caption alignnone" style="width: 510px"><img title="Michael Coles and Pinal Dave" src="http://www.pinaldave.com/bimg/mvpsummit/DSC03577.jpg" alt="Michael Coles and Pinal Dave" width="500" height="375" /><p class="wp-caption-text">Michael Coles and Pinal Dave</p></div>
<p>I spoke to Pinal Dave at the MVP Summit this week, and he challenged me to provide his readers with a practical demonstration of using XML in the database.  I took up the challenge, and decided to go one better by giving two practical demonstrations.</p>
<p style="text-align:justify;">This post is the first demonstration, which queries the SQL Server query plan cache and returns the cost of operations in the cache. <strong> The query simply shreds the cached XML query plans and grabs all the RelOp nodes, which represent all the operators used by the query plan.</strong> In the second post at <a href="http://sqlblog.com/blogs/michael_coles/archive/2009/03/03/practical-sql-server-xml-part-2.aspx" target="_blank">http://sqlblog.com/blogs/michael_coles/archive/2009/03/03/practical-sql-server-xml-part-2.aspx</a> I’ll demonstrate passing XML parameter “sets” into a stored procedure.  As a bonus, SQL MVP Jacob Sebastian has agreed to add a third post on his blog, at <a href="http://blog.beyondrelational.com/2009/03/practical-sql-server-xml-part-three.html" target="_blank">http://blog.beyondrelational.com/2009/03/practical-sql-server-xml-part-three.html</a> that will give a practical example of using XML Schema in SQL Server.</p>
<p style="text-align:justify;">The XML Query plans look like this in the cache (note that I simplified the XML and this is only a small portion that’s relevant):</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:gray;">&lt;</span><span style="color:black;">QueryPlan xmlns:p</span><span style="color:blue;">=</span><span style="color:darkred;">"http://schemas.microsoft.com/sqlserver/2004/07/showplan"<br />
</span><span style="color:black;">CachedPlanSize</span><span style="color:blue;">=</span><span style="color:darkred;">"112"<br />
</span><span style="color:black;">CompileTime</span><span style="color:blue;">=</span><span style="color:darkred;">"500"<br />
</span><span style="color:black;">CompileCPU</span><span style="color:blue;">=</span><span style="color:darkred;">"53"<br />
</span><span style="color:black;">CompileMemory</span><span style="color:blue;">=</span><span style="color:darkred;">"1968"</span><span style="color:gray;">&gt;</span></code>
</p>
<p style="text-align:justify;"><span style="color:black;">&#8230;</span></p>
<p style="text-align:justify;"><span style="color:gray;">&lt;</span><span style="color:black;">RelOp NodeId</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;0&#8243;<br />
</span><span style="color:black;">PhysicalOp</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;Sequence Project&#8221;<br />
</span><span style="color:black;">LogicalOp</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;Compute Scalar&#8221;<br />
</span><span style="color:black;">EstimateRows</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;227.951&#8243;<br />
</span><span style="color:black;">EstimateIO</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;0&#8243;<br />
</span><span style="color:black;">EstimateCPU</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;1.82361e-005&#8243;<br />
</span><span style="color:black;">AvgRowSize</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;5202&#8243;<br />
</span><span style="color:black;">EstimatedTotalSubtreeCost</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;930.972&#8243; </span><span style="color:black;">&#8230;</span><span style="color:gray;">&gt;</span>
</p>
<p style="text-align:justify;"><span style="color:black;">&#8230;</span></p>
<p style="text-align:justify;"><span style="color:gray;">&lt;</span><span style="color:black;">RelOp NodeId</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;1&#8243;<br />
</span><span style="color:black;">PhysicalOp</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;Segment&#8221;<br />
</span><span style="color:black;">LogicalOp</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;Segment&#8221;<br />
</span><span style="color:black;">EstimateRows</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;227.951&#8243;<br />
</span><span style="color:black;">EstimateIO</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;0&#8243;<br />
</span><span style="color:black;">EstimateCPU</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;4.55901e-006&#8243;<br />
</span><span style="color:black;">AvgRowSize</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;5202&#8243;<br />
</span><span style="color:black;">EstimatedTotalSubtreeCost</span><span style="color:blue;">=</span><span style="color:darkred;">&#8220;930.972&#8243; </span><span style="color:black;">&#8230;</span><span style="color:gray;">&gt;</span>
</p>
<p style="text-align:justify;"><span style="color:black;">&#8230;</span></p>
<p style="text-align:justify;"><span style="color:gray;">&lt;/</span><span style="color:black;">RelOp</span><span style="color:gray;">&gt;</span></p>
<p style="text-align:justify;"><span style="color:black;">&#8230;</span></p>
<p style="text-align:justify;"><span style="color:gray;">&lt;/</span><span style="color:black;">RelOp</span><span style="color:gray;">&gt;<br />
&lt;/</span><span style="color:black;">QueryPlan</span><span style="color:gray;">&gt;<br />
</span>
</p>
<p style="text-align:justify;">The equivalent graphical execution plan looks like this (note this is a partial screenshot):</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/bimg/xmlseries1.png" target="_blank"><img class="alignnone" src="http://www.pinaldave.com/bimg/xmlseries1.png" alt="" width="500" height="394" /></a></p>
<p style="text-align:justify;"><em><strong>(Click on image to see enlarged image)</strong></em></p>
<p style="text-align:justify;">(Note that you can save your graphical execution query plans as XML also – just right-click in the graphical execution query plan window and save it as a .sqlplan file. The .sqlplan file is in XML format – you can verify this by opening it in NotePad).</p>
<p style="text-align:justify;">Since SQL Server 2005 and 2008 store the query plans in the cache as XML we can get all of the same information in relational format.  The sample query below returns attributes of each operator in each query plan including physical and logical operators, estimated cost, estimated IO, estimated CPU cost, and an estimated number of rows returned.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">WITH </span><span style="color:black;">XMLNAMESPACES</span><span style="color:gray;">(</span><span style="color:blue;">DEFAULT </span><span style="color:red;">N'http://schemas.microsoft.com/sqlserver/2004/07/showplan'</span><span style="color:gray;">),<br />
</span><span style="color:black;">CachedPlans<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">ParentOperationID</span><span style="color:gray;">,<br />
</span><span style="color:black;">OperationID</span><span style="color:gray;">,<br />
</span><span style="color:black;">PhysicalOperator</span><span style="color:gray;">,<br />
</span><span style="color:black;">LogicalOperator</span><span style="color:gray;">,<br />
</span><span style="color:black;">EstimatedCost</span><span style="color:gray;">,<br />
</span><span style="color:black;">EstimatedIO</span><span style="color:gray;">,<br />
</span><span style="color:black;">EstimatedCPU</span><span style="color:gray;">,<br />
</span><span style="color:black;">EstimatedRows</span><span style="color:gray;">,<br />
</span><span style="color:black;">PlanHandle</span><span style="color:gray;">,<br />
</span><span style="color:black;">QueryText</span><span style="color:gray;">,<br />
</span><span style="color:black;">QueryPlan</span><span style="color:gray;">,<br />
</span><span style="color:black;">CacheObjectType</span><span style="color:gray;">,<br />
</span><span style="color:black;">ObjectType</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:black;">RelOp.op.value</span><span style="color:gray;">(</span><span style="color:red;">N'../../@NodeId'</span><span style="color:gray;">, </span><span style="color:red;">N'int'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">ParentOperationID</span><span style="color:gray;">,<br />
</span><span style="color:black;">RelOp.op.value</span><span style="color:gray;">(</span><span style="color:red;">N'@NodeId'</span><span style="color:gray;">, </span><span style="color:red;">N'int'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">OperationID</span><span style="color:gray;">,<br />
</span><span style="color:black;">RelOp.op.value</span><span style="color:gray;">(</span><span style="color:red;">N'@PhysicalOp'</span><span style="color:gray;">, </span><span style="color:red;">N'varchar(50)'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">PhysicalOperator</span><span style="color:gray;">,<br />
</span><span style="color:black;">RelOp.op.value</span><span style="color:gray;">(</span><span style="color:red;">N'@LogicalOp'</span><span style="color:gray;">, </span><span style="color:red;">N'varchar(50)'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">LogicalOperator</span><span style="color:gray;">,<br />
</span><span style="color:black;">RelOp.op.value</span><span style="color:gray;">(</span><span style="color:red;">N'@EstimatedTotalSubtreeCost '</span><span style="color:gray;">, </span><span style="color:red;">N'float'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">EstimatedCost</span><span style="color:gray;">,<br />
</span><span style="color:black;">RelOp.op.value</span><span style="color:gray;">(</span><span style="color:red;">N'@EstimateIO'</span><span style="color:gray;">, </span><span style="color:red;">N'float'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">EstimatedIO</span><span style="color:gray;">,<br />
</span><span style="color:black;">RelOp.op.value</span><span style="color:gray;">(</span><span style="color:red;">N'@EstimateCPU'</span><span style="color:gray;">, </span><span style="color:red;">N'float'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">EstimatedCPU</span><span style="color:gray;">,<br />
</span><span style="color:black;">RelOp.op.value</span><span style="color:gray;">(</span><span style="color:red;">N'@EstimateRows'</span><span style="color:gray;">, </span><span style="color:red;">N'float'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">EstimatedRows</span><span style="color:gray;">,<br />
</span><span style="color:black;">cp.plan_handle </span><span style="color:blue;">AS </span><span style="color:black;">PlanHandle</span><span style="color:gray;">,<br />
</span><span style="color:black;">st.</span><span style="color:blue;">TEXT AS </span><span style="color:black;">QueryText</span><span style="color:gray;">,<br />
</span><span style="color:black;">qp.query_plan </span><span style="color:blue;">AS </span><span style="color:black;">QueryPlan</span><span style="color:gray;">,<br />
</span><span style="color:black;">cp.cacheobjtype </span><span style="color:blue;">AS </span><span style="color:black;">CacheObjectType</span><span style="color:gray;">,<br />
</span><span style="color:black;">cp.objtype </span><span style="color:blue;">AS </span><span style="color:black;">ObjectType<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_exec_cached_plans cp<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">cp.plan_handle</span><span style="color:gray;">) </span><span style="color:black;">st<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_query_plan</span><span style="color:gray;">(</span><span style="color:black;">cp.plan_handle</span><span style="color:gray;">) </span><span style="color:black;">qp<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY qp.query_plan.nodes</span><span style="color:gray;">(</span><span style="color:red;">N'//RelOp'</span><span style="color:gray;">) </span><span style="color:black;">RelOp </span><span style="color:gray;">(</span><span style="color:black;">op</span><span style="color:gray;">)<br />
)<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:black;">PlanHandle</span><span style="color:gray;">,<br />
</span><span style="color:black;">ParentOperationID</span><span style="color:gray;">,<br />
</span><span style="color:black;">OperationID</span><span style="color:gray;">,<br />
</span><span style="color:black;">PhysicalOperator</span><span style="color:gray;">,<br />
</span><span style="color:black;">LogicalOperator</span><span style="color:gray;">,<br />
</span><span style="color:black;">QueryText</span><span style="color:gray;">,<br />
</span><span style="color:black;">CacheObjectType</span><span style="color:gray;">,<br />
</span><span style="color:black;">ObjectType</span><span style="color:gray;">,<br />
</span><span style="color:black;">EstimatedCost</span><span style="color:gray;">,<br />
</span><span style="color:black;">EstimatedIO</span><span style="color:gray;">,<br />
</span><span style="color:black;">EstimatedCPU</span><span style="color:gray;">,<br />
</span><span style="color:black;">EstimatedRows<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">CachedPlans<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">CacheObjectType </span><span style="color:blue;">= </span><span style="color:red;">N'Compiled Plan'</span><span style="color:gray;">; </span></code>
</p>
<p style="text-align:justify;">The results look similar to the following:</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/bimg/xmlseries2.png" target="_blank"><img class="alignnone" src="http://www.pinaldave.com/bimg/xmlseries2.png" alt="" width="499" height="148" /></a></p>
<p style="text-align:justify;"><em><strong>(Click on image to see enlarged image)</strong></em></p>
<p style="text-align:justify;">Since the XML query plan is hierarchical in structure, with operations nested within other operations, I’ve added the columns ParentOperationID and OperationID.  The ParentOperationID values point to the current operator’s parent operator.  I added the arrows in the results above to demonstrate.</p>
<p style="text-align:justify;">So what’s the practical use of this?  Well, once you have the XML query plan information in relational format it’s relatively easy to manipulate.  You can determine, for instance, the Top 10 most costly queries in your cache and the operators in those queries are the most expensive. You can even log this information to a table or send it out in other formats.</p>
<p style="text-align:justify;">In part 2 of this series I’ll talk about another practical use for SQL Server-based XML, at <a href="http://sqlblog.com/blogs/michael_coles/archive/2009/03/03/practical-sql-server-xml-part-2.aspx" target="_blank">http://sqlblog.com/blogs/michael_coles/archive/2009/03/03/practical-sql-server-xml-part-2.aspx</a>.  SQL Server MVP Jacob Sebastian will finish the series with part 3 on his blog at <a href="http://blog.beyondrelational.com/2009/03/practical-sql-server-xml-part-three.html" target="_blank">http://blog.beyondrelational.com/2009/03/practical-sql-server-xml-part-three.html</a>.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
Posted in Database, Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQL Utility, T SQL, Technology Tagged: SQL XML <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/3747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/3747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/3747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/3747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/3747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/3747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/3747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/3747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/3747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/3747/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=3747&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/03/17/sql-server-practical-sql-server-xml-part-one-query-plan-cache-and-cost-of-operations-in-the-cache/feed/</wfw:commentRss>
		<slash:comments>4</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/mvpsummit/DSC03577.jpg" medium="image">
			<media:title type="html">Michael Coles and Pinal Dave</media:title>
		</media:content>

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

		<media:content url="http://www.pinaldave.com/bimg/xmlseries2.png" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; UDF &#8211; Pad Ride Side of Number with 0 &#8211; Fixed Width Number Display</title>
		<link>http://blog.sqlauthority.com/2009/03/16/sql-server-udf-pad-ride-side-of-number-with-0-fixed-width-number-display/</link>
		<comments>http://blog.sqlauthority.com/2009/03/16/sql-server-udf-pad-ride-side-of-number-with-0-fixed-width-number-display/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 01:30:42 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></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[SQL Utility]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=3764</guid>
		<description><![CDATA[I had written article SQL SERVER &#8211; Pad Ride Side of Number with 0 &#8211; Fixed Width Number Display few days ago. Previous article was answer to the email which I had received:
Dear Pinal,
I have situation where I need to display my numbers in fixed format. Like
1 as 0000001
109 as 0000109
0987 as 0000987

Is there any [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=3764&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I had written article <strong><a href="http://blog.sqlauthority.com/2009/03/10/sql-server-pad-ride-side-of-number-with-0-fixed-width-number-display/" target="_blank">SQL SERVER &#8211; Pad Ride Side of Number with 0 &#8211; Fixed Width Number Display</a></strong> few days ago. Previous article was answer to the email which I had received:</p>
<p style="padding-left:30px;text-align:justify;"><em>Dear Pinal,</em></p>
<p style="padding-left:30px;text-align:justify;"><em>I have situation where I need to display my numbers in fixed format. Like</em></p>
<p style="padding-left:30px;text-align:justify;"><strong><em>1 as 0000001<br />
109 as 0000109</em><em><br />
0987 as 0000987</em></strong>
</p>
<p style="padding-left:30px;text-align:justify;"><em>Is there any string function in SQL Server which can do this?</em></p>
<p style="text-align:justify;">I had asked my blog readers to participate at the end of the article and I have received three very good suggestions. I am going to list all the three suggestions here. For me all the three suggestions are equally good. I suggest my readers to use any suggestion which they find easy to understand. I suggest to read my <a href="http://blog.sqlauthority.com/2009/03/10/sql-server-pad-ride-side-of-number-with-0-fixed-width-number-display/" target="_blank">previous article</a> before continuing this article further.</p>
<p style="text-align:justify;"><strong>Solution 1 by <a href="http://blog.sqlauthority.com/2009/03/10/sql-server-pad-ride-side-of-number-with-0-fixed-width-number-display/#comment-48722" target="_blank">Imran Mohammed</a></strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.FnExample<br />
</span><span style="color:gray;">(<br />
</span><span style="color:#434343;">@Size </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@Column_Value </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)<br />
)<br />
</span><span style="color:blue;">RETURNS TABLE<br />
AS<br />
RETURN<br />
</span><span style="color:gray;">(<br />
</span><span style="color:green;">-- Add the SELECT statement with parameter references here<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">RIGHT</span><span style="color:gray;">(</span><span style="color:magenta;">REPLICATE</span><span style="color:gray;">(</span><span style="color:black;">0</span><span style="color:gray;">, </span><span style="color:#434343;">@Size</span><span style="color:gray;">)<br />
+ </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:blue;">MAX</span><span style="color:gray;">), </span><span style="color:#434343;">@Column_Value</span><span style="color:gray;">), </span><span style="color:#434343;">@Size</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">ID<br />
</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Run following script to see output<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">dbo.FnExample </span><span style="color:gray;">(</span><span style="color:black;">7</span><span style="color:gray;">, </span><span style="color:black;">123</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;"><strong>Solution 2 by <a href="http://blog.sqlauthority.com/2009/03/10/sql-server-pad-ride-side-of-number-with-0-fixed-width-number-display/#comment-48725" target="_blank">Fenil Desai</a></strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">[dbo].[f_pad_before]<br />
</span><span style="color:gray;">( </span><span style="color:#434343;">@string </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:#434343;">@desired_length </span><span style="color:black;">INTEGER</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@pad_character </span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">) </span><span style="color:blue;">AS<br />
BEGIN<br />
</span><span style="color:green;">/* Prefix the required number of spaces to bulk up the string and<br />
then replace the spaces with the desired character */<br />
</span><span style="color:blue;">RETURN </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(<br />
</span><span style="color:magenta;">CASE<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@string</span><span style="color:gray;">) &lt; </span><span style="color:#434343;">@desired_length<br />
</span><span style="color:blue;">THEN </span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:magenta;">SPACE</span><span style="color:gray;">(</span><span style="color:#434343;">@desired_length </span><span style="color:gray;">- </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@string</span><span style="color:gray;">)), </span><span style="color:red;">' '</span><span style="color:gray;">, </span><span style="color:#434343;">@pad_character</span><span style="color:gray;">) + </span><span style="color:#434343;">@string<br />
</span><span style="color:blue;">ELSE </span><span style="color:#434343;">@string<br />
</span><span style="color:blue;">END<br />
</span><span style="color:gray;">))<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Run following script to see output<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.f_pad_before</span><span style="color:gray;">(</span><span style="color:red;">'123'</span><span style="color:gray;">,</span><span style="color:black;">7</span><span style="color:gray;">,</span><span style="color:red;">'0'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code></p>
<p><strong>Solution 3 by <a href="http://blog.sqlauthority.com/2009/03/10/sql-server-pad-ride-side-of-number-with-0-fixed-width-number-display/#comment-48766" target="_blank">CodeMonkey</a></strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.PadLeft<br />
</span><span style="color:gray;">(</span><span style="color:#434343;">@Value </span><span style="color:blue;">INT</span><span style="color:gray;">, </span><span style="color:#434343;">@PadWidth </span><span style="color:blue;">INT</span><span style="color:gray;">, </span><span style="color:#434343;">@PadChar </span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
RETURN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">REPLICATE</span><span style="color:gray;">(</span><span style="color:#434343;">@PadChar</span><span style="color:gray;">, </span><span style="color:#434343;">@PadWidth </span><span style="color:gray;">- </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@Value</span><span style="color:gray;">)), </span><span style="color:red;">''</span><span style="color:gray;">)<br />
+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:#434343;">@Value </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Run following script to see output<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.PadLeft</span><span style="color:gray;">(</span><span style="color:black;">123</span><span style="color:gray;">,</span><span style="color:black;">7</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;">Answer of all of the above script will be <strong>&#8216;0000123&#8242;</strong>.</p>
<p style="text-align:justify;">Again, I want to congratulate all three of my reader to participate in this interesting puzzle and would like to encourage other readers to participate in similar puzzles like this.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
Posted in Best Practices, Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQL Utility, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/3764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/3764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/3764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/3764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/3764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/3764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/3764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/3764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/3764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/3764/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=3764&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/03/16/sql-server-udf-pad-ride-side-of-number-with-0-fixed-width-number-display/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>
	</channel>
</rss>