<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>sqlserver &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/sqlserver/</link>
	<description>Feed of posts on WordPress.com tagged "sqlserver"</description>
	<pubDate>Sun, 29 Nov 2009 15:53:22 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Microsoft SQL Server 2008 : High Availability Always On Technologies]]></title>
<link>http://sqlhero.wordpress.com/2009/11/28/microsoft-sql-server-2008-high-availability-always-on-technologies/</link>
<pubDate>Sat, 28 Nov 2009 18:51:26 +0000</pubDate>
<dc:creator>mohtantawy</dc:creator>
<guid>http://sqlhero.wordpress.com/2009/11/28/microsoft-sql-server-2008-high-availability-always-on-technologies/</guid>
<description><![CDATA[Here are the list of options that can help you in deciding and managing high availabilty options in ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Here are the list of options that can help you in deciding and managing high availabilty options in SQL Server 2008</p>
<p><strong>Increased Availability</strong></p>
<ul>
<li>Database Mirroring</li>
<li>Log Shipping</li>
<li>Failover Clustering</li>
<li>Geographically Dispersed Failover Clustering</li>
<li>Peer-to-Peer Replication</li>
</ul>
<p><strong>Decreased Downtime</strong></p>
<ul>
<li>Fast Database Recovery</li>
<li>Backup and Restore</li>
<li>Checksum on Data Pages</li>
<li>Online Index Operations</li>
<li>Online, Piecemeal, and Page-Level Restore</li>
<li>Partial Database Availability</li>
<li>Snapshot Isolation</li>
</ul>
<p><strong>Dynamic Configuration</strong></p>
<ul>
<li>Enhanced Manageability</li>
<li>Database Snapshots</li>
<li>Table and Index Partitioning</li>
<li>Backup and Restore</li>
<li>Dedicated Administrator Connection</li>
<li>Resource Governor</li>
</ul>
<p>for More info please check the white paper of Microsoft SQL Server 2008 High Availabilty &#8211; Always on Technologies<br />
<a href="http://www.microsoft.com/sqlserver/2008/en/us/wp-sql-2008-high-availability.aspx">http://www.microsoft.com/sqlserver/2008/en/us/wp-sql-2008-high-availability.aspx</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server Code Name]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/24/sql-server-code-name/</link>
<pubDate>Tue, 24 Nov 2009 06:32:46 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/24/sql-server-code-name/</guid>
<description><![CDATA[SQL Server Code Name Yesterday, I came across a very interesting question on one of the SQL Servers ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>SQL Server Code Name</strong></p>
<p>Yesterday, I came across a very interesting question on one of the SQL Servers Online Forums.</p>
<p><span style="color:#ff0000;"><strong>Question</strong> – What is the code name of SQL Server 2005?</span></p>
<p>Well I knew that the Microsoft gives code names to it products when they are in developmental stages. But I never came across the code name for SQL Serves!</p>
<p>So I did some research on Net to find code name of all the SQL Server Release till date. They are listed below.</p>
<table border="2" cellspacing="0" cellpadding="2" width="479">
<tbody>
<tr>
<td width="357" valign="bottom"><strong>SQL   Server Release</strong></td>
<td width="220" valign="bottom"><strong>Project   Code Name</strong></td>
</tr>
<tr>
<td width="357" valign="bottom">SQL Server   6.0</td>
<td width="220" valign="bottom">SQL95</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server Enterprise Manager</td>
<td width="220" valign="bottom">Starfighter</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 6.5</td>
<td width="220" valign="bottom">Hydra</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 7.0</td>
<td width="220" valign="bottom">Sphinx</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 7.0</td>
<td width="220" valign="bottom">Plato</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 2000 (32-bit)</td>
<td width="220" valign="bottom">Shiloh</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 2000 (64-bit)</td>
<td width="220" valign="bottom">Liberty</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server Reporting Services</td>
<td width="220" valign="bottom">Rosetta</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 2005</td>
<td width="220" valign="bottom">Yukon</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 2005 Mobile Edition</td>
<td width="220" valign="bottom">Laguna</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 2008</td>
<td width="220" valign="bottom">Katmai /   Akadia</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Report Designer 2.0</td>
<td width="220" valign="bottom">Blue</td>
</tr>
<tr>
<td width="357" valign="bottom">SQL   Server 2008R2</td>
<td width="220" valign="bottom">Killimanjaro</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Sql Azure la base de datos en la nube]]></title>
<link>http://highscalability.wordpress.com/2009/11/23/sql-azure-la-base-de-datos-en-la-nube-2/</link>
<pubDate>Mon, 23 Nov 2009 08:18:59 +0000</pubDate>
<dc:creator>Alex</dc:creator>
<guid>http://highscalability.wordpress.com/2009/11/23/sql-azure-la-base-de-datos-en-la-nube-2/</guid>
<description><![CDATA[SQL Azure nos permite desarrollar bases de datos relacionales en la nube construida sobre la tecnolo]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div id="_mcePaste" style="text-align:justify;"><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/1pPXzvSS0j0&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><embed src='http://www.youtube.com/v/1pPXzvSS0j0&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='transparent'></embed></object></span></div>
<div style="text-align:justify;">
<div style="text-align:justify;">SQL Azure nos permite desarrollar bases de datos relacionales en la nube construida sobre la tecnología SQL Server, esto nos permite construir aplicaciones de mediano tamaño que puedan escalar fácilmente y que tenga una alta disponibilidad, SQL Azure tiene completo soporte para T-SQL ademas que nos libra de la necesidad de instalar software o realizar la administración física de la base de datos, esto al mismo tiempo se traduce en una disminución de los costos de despliegue y mantenimiento.</div>
<p><!--more Seguir leyendo--></p>
<div style="text-align:justify;">Con SQL Azure podemos crear tablas, vistas, indices, procedimientos almacenados, triggers, funciones, tablas temporales, constraints, ademas de poseer un subconjunto de los procedimientos y vistas de sistema.</div>
<div>Pueden acceder a la versión de SQL Server 2008 Management Studio con soporte para SQL Azure <a href="http://go.microsoft.com/fwlink/?LinkID=168734&#38;clcid=0x409">aqui</a>.</div>
<div>Para empezar a usar SQL Azure necesitas:</div>
<div>
<ul>
<li>Descargar el <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=413E88F8-5966-4A83-B309-53B7B77EDF78&#38;displaylang=en">Windows Azure Platform Training Kit</a></li>
<li>Tener: Windows 7; Windows Server 2008; Windows Vista</li>
<li>Windows Vista SP1 (cuando instale en Windows Vista)</li>
<li>IIS 7.0 (with ASP.NET, WCF HTTP Activation and optionally CGI)</li>
<li>Microsoft Visual Studio 2008 SP1, Microsoft Visual Studio 2010 Beta 2 o Microsoft Visual Web Developer 2008 Express Edition with SP1</li>
<li>SQL Server 2005 Express Edition (o superior)</li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=145526">Hotfix: Native Debugging Improvements</a> (no requerido para Visual Studio 2010)</li>
<li><a href="https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=16827&#38;wa=wsignin1.0">Hotfix: Improve Visual Studio Stability</a> (no requerido para Windows 7 RC or later)</li>
<li><a href="http://support.microsoft.com/kb/967131">Hotfix: Support for FastCGI on the Development Fabric</a></li>
<li>(no requerido para Windows 7 RC o superior, o Windows Server 2008 SP2 o superior )</li>
<li>Descargar <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=8d75d4f7-77a4-4adf-bce8-1b10608574bb&#38;displaylang=en">Tool &#38; SDK</a></li>
</ul>
</div>
<div>Artículos relacionados:</div>
<div><a href="http://highscalability.wordpress.com/2009/09/08/que-es-windows-azure/">Que es Windows Azure?</a></div>
<div style="text-align:justify;"><a href="http://highscalability.wordpress.com/2009/09/10/como-hospedar-tu-aplicacion-usando-los-servicios-de-windows-azure/">Como hospedar tu aplicación usando los servicios de Windows Azure</a></div>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL SERVER - A Common Design Problem - Should the Primary Key Always be a Clustered Index]]></title>
<link>http://blog.sqlauthority.com/2009/11/23/sql-server-a-common-design-problem-should-the-primary-key-always-be-a-clustered-index/</link>
<pubDate>Mon, 23 Nov 2009 01:30:34 +0000</pubDate>
<dc:creator>pinaldave</dc:creator>
<guid>http://blog.sqlauthority.com/2009/11/23/sql-server-a-common-design-problem-should-the-primary-key-always-be-a-clustered-index/</guid>
<description><![CDATA[In SQL Server, whenever we create any key, a Primary Key automatically creates clustered index on th]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;">In SQL Server, whenever we create any key, a Primary Key automatically creates clustered index on the same. I like this feature and I use this feature every now and then.</p>
<p style="text-align:justify;">The question is does the change of any column as Primary Key should also create a Clustered Index? Moreover, is there any case, where one would not do the same?</p>
<p style="text-align:justify;">One of the recent conversations I had with one SQL Expert is with regard to the SSN number. The discussion was that SSN numbers are always unique and never repeated and hence are the best candidates for primary key. Additionally SSN numbers contains dashes (-), which make the datatype of the SSN numbers as String (VARCHAR or NVARCHAR). A clustered index on an integer usually performs better over a clustered index on an integer and makes the DBA to choose Primary Key of datatype Integer. At one point in our conversation, we discussed that if SSN number should be a Unique Constraint and if there should be another Identity Column as the Primary Key.</p>
<p style="text-align:justify;">Some of the questions from our interesting discussion are as follows:</p>
<p style="text-align:justify;"><strong><em>Would you have the datatype of your Primary Key as string?<br />
Would you treat SSN as string datatype or remove the dashes and change it into an integer?<br />
Do you have a real life example, where your primary key is not a clustered index?<br />
What are the best practices for SSN number to store in database and obtain optimal performance?</em></strong></p>
<p style="text-align:justify;">I will post an interesting answer discussing this subject in a separate post 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>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL SERVER - Remove Bookmark Key Lookup - 4 Different Ideas]]></title>
<link>http://blog.sqlauthority.com/2009/11/22/sql-server-remove-bookmark-key-lookup-4-different-ideas/</link>
<pubDate>Sun, 22 Nov 2009 01:30:12 +0000</pubDate>
<dc:creator>pinaldave</dc:creator>
<guid>http://blog.sqlauthority.com/2009/11/22/sql-server-remove-bookmark-key-lookup-4-different-ideas/</guid>
<description><![CDATA[I quite often get request to summarized my ideas about Removing bookmark lookup on this blog post. B]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;">I quite often get request to summarized my ideas about Removing bookmark lookup on this blog post. Bookmark lookup or key lookup are bad for any query as they force query engine to lookpup corresponding row in the table or index as it does not find required data from just reading the data.</p>
<p style="text-align:justify;">Here are list of my four post written on the same subject.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 3</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/" target="_blank">SQL SERVER – Removing Key Lookup – Seek Predicate – Predicate – An Interesting Observation Related to Datatypes</a></p>
<p style="text-align:justify;">Let me know your opinion about the same and I am interested to here what you have to add to this subject.</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>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQLAuthority News - Book Review - Expert SQL Server 2008 Encryption by Michael Coles]]></title>
<link>http://blog.sqlauthority.com/2009/11/20/sqlauthority-news-book-review-expert-sql-server-2008-encryption-by-michael-coles/</link>
<pubDate>Fri, 20 Nov 2009 01:30:03 +0000</pubDate>
<dc:creator>pinaldave</dc:creator>
<guid>http://blog.sqlauthority.com/2009/11/20/sqlauthority-news-book-review-expert-sql-server-2008-encryption-by-michael-coles/</guid>
<description><![CDATA[Expert SQL Server 2008 Encryption (Paperback) Michael Coles (Author), Rodney Landrum (Author) Link t]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;"><strong>Expert SQL Server 2008 Encryption (Paperback)</strong><br />
<em>Michael Coles (Author), Rodney Landrum (Author)</em></p>
<p style="text-align:justify;"><em><img class="alignnone" src="http://www.pinaldave.com/bimg/encryptionbook.gif" alt="" width="272" height="359" /><br />
</em></p>
<p style="text-align:justify;"><strong><a href="http://www.amazon.com/dp/1430224649/" target="_blank">Link to Amazon</a></strong></p>
<p style="text-align:justify;">“What is your opinion on encryption? What I mean is: In a world filled with data, how do you see encryption?” This is the precise question Michael Coles posed to me on March 3<sup>rd</sup> of this year, while we were heading to Starbucks in Seattle. We were both attending the Microsoft MVP Summit there.</p>
<p style="text-align:justify;">In the information era, security has become one of the most vital aspects of life. Although the topic may seem a little mundane, its importance cannot be overemphasized. It is the pillar of the information age and I shudder to think where we would be without it. We don’t leave our houses unlocked and risk thieves or opportunists taking off with our valuables. We also often take precautions, not only to preserve the precious, but also to avoid the sheer hassle of replacement and misuse. So too it should be with our information.</p>
<p style="text-align:justify;">Encryption’s roots are extremely old and it has resolved numerous security problems over the years. In days gone by, couriers were entrusted with letters sealed with a royal wax stamp. If on delivery, the seal was broken, it was obvious that there had been a security breach. This very concept evolved as CRC checksum and developed into a complex algorithm.  While CRC checksum alerted the end user to the fact that content had been modified, its limitation was that it allowed manipulation of the content to occur in the first place. With encryption, only the authenticated owner can access and modify content.</p>
<p style="text-align:justify;">In response to Michael’s question, I began to tell him what I knew about public and private keys. He looked at me doubtfully and asked me directly if I had ever used encryption in my career. My reluctant answer to this was “No”. He strongly suggested that I not underestimate its capabilities and explore its possibilities. I took his advice and have since implemented encryption for many of my clients, who are now far safer from unauthorized access to data.</p>
<p style="text-align:justify;">To be very honest, in my experience, not many people know much about the subject beyond a little about public and private keys.  You do not often find experts discussing symmetric and asymmetric keys, which are just the tip of the iceberg. SQL Server has come a long way with regard to security. Encryption has taken on a whole new meaning in SQL Server 2008. There are many new features such as Extensible Key Management, Transparent Data Encryption, not to mention the pre-2008 ones such as cryptographic hashing, SQL CLR and many more. In performance terms, these are great enhancements.</p>
<p style="text-align:justify;">The one exception is Transparent Data Encryption, where the whole database is encrypted. This can considerably reduce performance if the SQL Server box is not sufficiently powerful. It this is the case, it is a good time to offload all the encryption and decryption to third-party hardware. SQL Server allows third-party management of encryption and decryption through Extensible Key Management.</p>
<p style="text-align:justify;">Extending the earlier courier analogy, consider the fact that even if our letter is secure and safe in our hands, as soon as we hand it to the courier it is exposed to risk and can be compromised. SQL Server 2008 has many new features, which secure data while it is being communicated between applications. A number of features were introduced that check whether data is manipulated during transmission.</p>
<p style="text-align:justify;">Data is everywhere and taking in terms of Terra Bytes (TB) is the current reality. When a large amount of data needs to be handled, there are two major challenges. The first challenge is the actual encryption process and the resources needed to perform it. The second challenge is how to use the data once it has been encrypted.  In a regular database searching through TBs of data can take a very long time. Imagine how long this could take in and encrypted database?</p>
<p style="text-align:justify;">In Seattle, Michael and I discussed these challenges and a few more subjects. The discussion lasted more than four hours. I have always known Michael to be an excellent author. He is renowned in the industry for his expertise of XML and Full Text Search. To my mind, he is an expert who has the extraordinary ability of relating complex concepts in simple terms. No matter how long, boring or complicated the topic, his delivery is always sweet, like chocolate that melts in the mouth.</p>
<p style="text-align:justify;">Michael always addresses uncommon subjects. Perhaps his experience as a Sergeant in the army has given him the spirit to explore the unexplored.  I have never before encountered a single book on the subject of encryption for SQL Server and Michael’s will a “first”.</p>
<p style="text-align:justify;">I recently had the pleasure of reading it and especially like the manner in which he and his co-author, Rodney, explain the significance of encryption. While many of the concepts covered are domain-specific, quite a few topics are common to all and the appendix is a “must read” for anyone planning a security strategy. One thing that really makes this book special is the fact that each module is written independently and you can find solutions by simply reading the relevant one.</p>
<p style="text-align:justify;">I am a hands-on developer and only like books that have a lot of workable examples. With the exception of the first chapter, the book is filled with examples and hands-on experiments. The first chapter in itself is quite unique, as it not only provides a introduction to encryption, but also the very interesting history of encryption.  Even non-technical readers will enjoy this.</p>
<p style="text-align:justify;"><strong>Summary:</strong><br />
It is my great pleasure to welcome this one-of-a- kind book to the SQL Server world. There is no doubt that this book is exceptional and will inspire anyone one who is ready to take their current security mechanism to the next level using encryption.</p>
<p style="text-align:justify;"><strong>Stars : 5 Stars</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>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - DBCC Commands]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/19/sql-server-dbcc-commands/</link>
<pubDate>Thu, 19 Nov 2009 12:53:41 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/19/sql-server-dbcc-commands/</guid>
<description><![CDATA[DBCC (Database consistency checker) are used to check the consistency of the databases. The DBCC com]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>DBCC</strong><strong> (Database consistency checker</strong>) are used to check the consistency of the databases. The DBCC commands are most useful for performance and trouble shooting exercises.</p>
<p>I have listed down and explained all the DBCC commands available in SQL Server 2005, with examples.</p>
<p>The DBCC Commands broadly falls into four categories:</p>
<ul>
<li>Maintenance</li>
<li>Informational</li>
<li>Validation</li>
<li>Miscellaneous</li>
</ul>
<h2><span style="color:#ff00ff;"><strong>Maintenance Commands</strong></span></h2>
<p>Performs maintenance tasks on a database, index, or filegroup.</p>
<p>1. <strong>CLEANTABLE</strong> – Reclaims space from the dropped variable-length columns in tables or index views.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> CLEANTABLE (<span style="color:#ff0000;">&#8216;AdventureWorks&#8217;,'Person.Contact&#8217;</span>,0)</p>
</div>
<p>2. <strong>DBREINDEX</strong> – Builds one or more indexes for the table in the specified database. (Will be <strong>removed</strong> in the future version, use <span style="color:#0000ff;">ALTER INDEX</span> instead)</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE </span>AdventureWorks</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> DBREINDEX (<span style="color:#ff0000;">&#8216;Person.Contact&#8217;,'PK_Contact_ContactID&#8217;</span>,80)</p>
</div>
<p>3. <strong>DROPCLEANBUFFERS</strong> – Removes all clean buffers from buffer pool.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> DROPCLEANBUFFERS</p>
</div>
<p>4. <strong>FREEPROCCACHE</strong> – Removes all elements from the procedure cache</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> FREEPROCCACHE</p>
</div>
<p>5. <strong>INDEXDEFRAG</strong> – Defragments indexes of the specified table or view.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC </span>INDEXDEFRAG (<span style="color:#ff0000;">&#8216;AdventureWorks&#8217;, &#8216;Person.Address&#8217;</span>, PK_Address_AddressID)</p>
</div>
<p>6. <strong>SHRINKDATABASE</strong> – Shrinks the size of the data and log files in the specified database</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC </span>SHRINKDATABASE (<span style="color:#ff0000;">&#8216;AdventureWorks</span>&#8216;, 10)</p>
</div>
<p>7. <strong>SHRINKFILE</strong> &#8211; Shrinks the size of the specified data or log file for the current database or empties a file by moving the data from the specified file to other files in the same filegroup, allowing the file to be removed from the database.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE</span> AdventureWorks;</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Shrink the truncated log file to 1 MB.</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> SHRINKFILE (AdventureWorks_Log, 1)</p>
</div>
<p>8. <strong>UPDATEUSAGE</strong> &#8211; Reports and corrects pages and row count inaccuracies in the catalog views.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> UPDATEUSAGE (AdventureWorks)</p>
</div>
<h2><span style="color:#ff00ff;"><strong>Informational Commands</strong></span></h2>
<p>Performs tasks that gather and display various types of information.</p>
<p>1. <strong>CONCURRENCYVIOLATION</strong> &#8211; is maintained for backward compatibility. It runs but returns no data.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> CONCURRENCYVIOLATION</p>
</div>
<p>2.<strong> INPUTBUFFER</strong> &#8211; Displays the last statement sent from a client to an instance of Microsoft SQL Server 2005.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> INPUTBUFFER (52)</p>
</div>
<p>3. <strong>OPENTRAN</strong> &#8211; Displays information about the oldest active transaction and the oldest distributed and nondistributed replicated transactions, if any, within the specified database.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> OPENTRAN;</p>
</div>
<p>4. <strong>OUTPUTBUFFER</strong> &#8211; Returns the current output buffer in hexadecimal and ASCII format for the specified session_id.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> OUTPUTBUFFER (52)</p>
</div>
<p>5. <strong>PROCCACHE</strong> &#8211; Displays information in a table format about the procedure cache.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC </span>PROCCACHE</p>
</div>
<p>6. <strong>SHOW</strong><strong>_STATISTICS</strong> – Displays the current distribution statistics for the specified target on the specified table</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE </span>AdventureWorks</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> SHOW_STATISTICS (<span style="color:#ff0000;">&#8216;Person.Address&#8217;</span>, AK_Address_rowguid)</p>
</div>
<p>7. <strong>SHOWCONTIG</strong> &#8211; Displays fragmentation information for the data and indexes of the specified table or view.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE</span> AdventureWorks</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC </span>SHOWCONTIG (<span style="color:#ff0000;">&#8216;HumanResources.Employee&#8217;</span>);</p>
</div>
<p>8. <strong>SQLPERF</strong> &#8211; Provides transaction log space usage statistics for all databases. It can also be used to reset wait and latch statistics.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> SQLPERF(LOGSPACE)</p>
</div>
<p>9. <strong>TRACESTATUS</strong> &#8211; Displays the status of trace flags.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC </span>TRACESTATUS(-1)</p>
</div>
<p>10. <strong>USEROPTIONS</strong> &#8211; Returns the SET options active (set) for the current connection.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> USEROPTIONS</p>
</div>
<p><strong> </strong></p>
<h2><span style="color:#ff00ff;"><strong>Validation Commands</strong></span></h2>
<p>Performs validation operations on a database, table, index, catalog, filegroup, or allocation of database pages.</p>
<p>1. <strong>CHECKALLOC</strong> &#8211; Checks the consistency of disk space allocation structures for a specified database.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> CHECKALLOC (AdventureWorks)</p>
</div>
<p>2. <strong>CHECKCATALOG</strong> &#8211; Checks for catalog consistency within the specified database.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC </span>CHECKCATALOG (AdventureWorks)</p>
</div>
<p>3. <strong>CHECKCONSTRAINTS</strong> &#8211; Checks the integrity of a specified constraint or all constraints on a specified table in the current database.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> CHECKCONSTRAINTS WITH ALL_CONSTRAINTS</p>
</div>
<p>4. <strong>CHECKDB</strong> &#8211; Checks the logical and physical integrity of all the objects in the specified database.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> CHECKDB (AdventureWorks)</p>
</div>
<p>5. <strong>CHECKFILEGROUP</strong> &#8211; Checks the allocation and structural integrity of all tables and indexed views in the specified filegroup of the current database.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE</span> AdventureWorks</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> CHECKFILEGROUP</p>
</div>
<p>6. <strong>CHECKIDENT</strong> &#8211; Checks the current identity value for the specified table and, if it is needed, changes the identity value.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE </span>AdventureWorks;</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> CHECKIDENT (<span style="color:#ff0000;">&#8216;HumanResources.Employee&#8217;</span>)</p>
</div>
<p>7. <strong>CHECKTABLE</strong> &#8211; Checks the integrity of all the pages and structures that make up the table or indexed view.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE</span> AdventureWorks;</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> CHECKTABLE (<span style="color:#ff0000;">&#8216;HumanResources.Employee&#8217;</span>)</p>
</div>
<h2><span style="color:#ff00ff;"><strong>Miscellaneous Commands</strong></span></h2>
<p>Performs miscellaneous tasks such as enabling trace flags or removing a DLL from memory.</p>
<p>1. <strong>dllname (FREE)</strong> &#8211; Unloads the specified extended stored procedure DLL from memory.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> xp_sample (FREE)</p>
</div>
<p>2. <strong>TRACEOFF</strong> &#8211; Disables the specified trace flags.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> TRACEOFF (3205)</p>
</div>
<p>3. <strong>HELP</strong> &#8211; Returns syntax information for the specified DBCC command.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; List all the DBCC commands</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> HELP (<span style="color:#ff0000;">&#8216;?&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Show the Syntax for a given DBCC commnad</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> HELP (<span style="color:#ff0000;">&#8216;checkcatalog&#8217;</span>)</p>
</div>
<p>4. <strong>TRACEON</strong> &#8211; Enables the specified trace flags.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">DBCC</span> TRACEON (3205)</p>
</div>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Piano]]></title>
<link>http://igorborges.wordpress.com/2009/11/18/piano/</link>
<pubDate>Thu, 19 Nov 2009 01:34:39 +0000</pubDate>
<dc:creator>Borges</dc:creator>
<guid>http://igorborges.wordpress.com/2009/11/18/piano/</guid>
<description><![CDATA[Quarta-feira, 18 de Novembro de 2009, 23h13 &#8220;Se não está doendo agora, não deve doer depois. P]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Quarta-feira, 18 de Novembro de 2009, 23h13</p>
<p>&#8220;<em>Se não está doendo agora, não deve doer depois. Pode colocar</em>&#8221; . Agora posso dizer que dói. E é uma dor irritante, e expansiva, literalmente. Estou falando desses elásticos em minha boca. Oito. Cor verde-água. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Parece que em dois dias para de doer, aí vem a aparelhagem definitiva. Bem que a dentista disse que, perguntando pra quem já colocou aparelho, o que ele mais se lembra é desses elásticos.</p>
<p>Bom, provinha bem fácil de português hoje. Quer dizer, era pra ser difícil, mas a professora facilitou nossa vida.</p>
<blockquote><p>Aquela senhora tem um piano<br />
Que é agradável mas não é o correr dos rios<br />
Nem o murmúrio que as árvores fazem&#8230;</p>
<p>Para que é preciso ter um piano?<br />
O melhor é ter ouvidos<br />
E amar a Natureza.</p></blockquote>
<p>- Alberto Caeiro, heterônimo de Fernando Pessoa em &#8220;O Guardador de Rebanhos&#8221; (<a href="http://books.google.com.br/books?id=RV7IIunbTGsC&#38;lpg=PA100&#38;ots=B2PDMe9YaW&#38;dq=guardador%20de%20rebanhos%20piano&#38;pg=PA100#v=onepage&#38;q=&#38;f=false">^</a>)<br />
&#8220;Lindo!&#8221; &#8211; BORGES, Susi M. K. S.</p>
<p>Apesar de tudo, eu ri de muitos fatos que aconteceram hoje. O principal deles, eu mexendo em um servidor na escola com conta de administrador. Por conexão remota, eu loguei naquela servidor, arrumei umas coisas e outras, e vi que um serviço não estava funcionando. Como ele dependia da rede, eu simplesmente desabilitei o adaptador de rede. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Cheguei no T.I.: &#8220;<em>moço, a gente tava usando o servidor, mas ele caiu do nada e não volta mais..</em>&#8220;. hsuahsaushauhsa</p>
<p>Outra coisa engraçadíssima foi a discussão do Andrey com a Juh, <!-- que eu tive acesso à conversa, e ri demais dela. Sério, eu realmente nunca gostei do jeito da Juh. Ela é uma pessoa.. boa, mas é muito tapada, e não se dá conta disso. Não adianta, todo mundo já tentou conversar com ela, ver se ela faz por graça, ou não, mas ela parece não se importar, e vive essa vida "medilcre" (shaushausha). Ninguém mais quer fazer trabalho com ela. Veja o Bruno, a Bia. E ela não faz nada pra tentar melhorar essa situação. Isso que eu odeio nela: a falta de atitude no sentido de recuperar sua moral, sua própria pessoa, e tentar ser mais normal; inclusive parar de falar que vai ficar de recuperação e estudar mais para as provas, e melhorar seus trabalhos. -->(&#8230;).</p>
<p>23h29</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[List of Table Constraints in sql server]]></title>
<link>http://viralsarvaiya.wordpress.com/2009/11/18/list-of-table-constraints-in-sql-server/</link>
<pubDate>Wed, 18 Nov 2009 05:55:15 +0000</pubDate>
<dc:creator>viralsarvaiya</dc:creator>
<guid>http://viralsarvaiya.wordpress.com/2009/11/18/list-of-table-constraints-in-sql-server/</guid>
<description><![CDATA[There five type of constrains provided by SQL Server. We shall see each one of then in details 1. Pr]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>There five type of constrains provided by SQL Server. We shall see each one of then in details</p>
<p>1. Primary Key Constraint</p>
<p>A primary key is used to uniquely identify each row in a table. A primary key can consist of one or more then more columns in table. When they consist of more then one column they are called composite key. It ensures unique non-null key.</p>
<p>CREATE TABLE Student(<br />
StudID INT PRIMARY KEY,<br />
StudName VARCHAR(50)<br />
)</p>
<p>or</p>
<p>ALTER TABLE Department ADD PRIMARY KEY (DeptID)</p>
<p>2. Foreign Key Constraint</p>
<p>A foreign key is a field in a table that matches the primary key column of another table. It establishes and enforces a link between data of two tables. It ensures that value points to a valid key.</p>
<p>CREATE TABLE Subjects(<br />
SubID INT,<br />
SubName VARCHAR(50),<br />
StudID INT FOREIGN KEY REFERENCES Student(StudID),<br />
TotalMarks INT,<br />
)</p>
<p>or</p>
<p>ALTER TABLE Subjects(ADD CONSTRAINT StudID_Fk<br />
FOREIGN KEY (StudID) REFERENCES Student(StudID)</p>
<p>3. Unique Constraint</p>
<p>It is similar to Primary Key Constraint. It ensures that every value in the column is unique value. It allows one NULL value.</p>
<p>CREATE TABLE Employee(<br />
EmpID INT,<br />
FirstName VARCHAR(50),<br />
LastName VARCHAR(50),<br />
DeptID INT,<br />
Salary INT,<br />
ProjectCode INT UNIQUE,<br />
)</p>
<p>or</p>
<p>ALTER TABLE Employee ADD UNIQUE (ProjectCode)</p>
<p>4. Nullability Constraint</p>
<p>It defines whether a column will accept a NULL value or not. It is referred to as nullability of the column.</p>
<p>CREATE TABLE Employee(<br />
EmpID INT,<br />
FirstName VARCHAR(50) NOT NULL,<br />
LastName VARCHAR(50),<br />
DeptID INT,<br />
Salary INT,<br />
ProjectCode INT<br />
)</p>
<p>or</p>
<p>ALTER TABLE Employee ALTER COLUMN FirstName VARCHAR(50) NOT NULL;</p>
<p>5. Check Constraint</p>
<p>Check Constraint is extensively used to enforcement of general data-validation rules or simple business rules. Such as correct date range, max value that can be inserted into a table, etc.</p>
<p>CREATE TABLE Employee(<br />
EmpID INT,<br />
FirstName VARCHAR(50),<br />
LastName VARCHAR(50),<br />
DeptID INT,<br />
Salary INT,<br />
ProjectCode INT,<br />
CONSTRAINT chk_sal CHECK (Salary BETWEEN 1000 AND 25000)<br />
)</p>
<p>or</p>
<p>ALTER TABLE Employee<br />
ADD CONSTRAINT chk_salary CHECK (Salary BETWEEN 1000 AND 25000)</p>
<p>Now in the below example show the all the Constraints in one table,</p>
<p>CREATE TABLE Employee(<br />
EmpID INT PRIMARY KEY,<br />
FirstName VARCHAR(50) NOT NULL,<br />
LastName VARCHAR(50),<br />
DeptID INT FOREIGN KEY REFERENCES Department(DeptID),<br />
Salary INT,<br />
ProjectCode INT UNIQUE,<br />
CONSTRAINT chk_salary CHECK (Salary BETWEEN 1000 AND 25000)<br />
)</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL SERVER - Size of Index Table - A Puzzle to Find Index Size for Each Index on Table]]></title>
<link>http://blog.sqlauthority.com/2009/11/18/sql-server-size-of-index-table-a-puzzle-to-find-index-size-for-each-index-on-table/</link>
<pubDate>Wed, 18 Nov 2009 01:30:16 +0000</pubDate>
<dc:creator>pinaldave</dc:creator>
<guid>http://blog.sqlauthority.com/2009/11/18/sql-server-size-of-index-table-a-puzzle-to-find-index-size-for-each-index-on-table/</guid>
<description><![CDATA[It is very easy to find out some basic details of any table using the following Stored Procedure. US]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;">It is very easy to find out some basic details of any table using the following Stored Procedure.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_spaceused </span><span style="color:black;">[HumanResources.Shift]<br />
GO</span></code></p>
<p style="text-align:justify;">Above query will return following resultset</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/sp_spaceused1.jpg" alt="" width="369" height="153" /></p>
<p style="text-align:justify;">The above SP provides basic details such as rows, data size in table, and Index size of all the indexes on the table.</p>
<p style="text-align:justify;">If we look at this carefully, a total of three indexes can be found on the table HumanResources.Shift.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.indexes<br />
</span><span style="color:blue;">WHERE </span><span style="color:magenta;">OBJECT_ID </span><span style="color:blue;">= </span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">(</span><span style="color:red;">'HumanResources.Shift'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">The above query will give result with query listing all the index on the table.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/indexspace.jpg" alt="" width="500" height="248" /></p>
<p style="text-align:justify;">There is a small puzzle for all of you here. The puzzle is to write a query that will return the size for each index that is listed in above query. We need a query that will return an additional column in the above listed query and it should contain the size of the index. In our case, we will have three different sizes, which should add up to a total of 40 KB as shown in earlier query, where the total size is displayed.</p>
<p style="text-align:justify;">I will publish the solution with due credit on this blog.</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>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQLAuthority News - Notes of Excellent Experience at SQL PASS 2009 Summit, Seattle]]></title>
<link>http://blog.sqlauthority.com/2009/11/16/sqlauthority-news-notes-of-excellent-experience-at-sql-pass-2009-summit-seattle/</link>
<pubDate>Mon, 16 Nov 2009 01:30:59 +0000</pubDate>
<dc:creator>pinaldave</dc:creator>
<guid>http://blog.sqlauthority.com/2009/11/16/sqlauthority-news-notes-of-excellent-experience-at-sql-pass-2009-summit-seattle/</guid>
<description><![CDATA[Update: Do not forget to checkout last three photos and follow me on twitter (of course!) I have pre]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;"><span style="color:#ff0000;"><span style="text-decoration:underline;"><strong>Update:</strong></span></span> Do not forget to checkout <em><strong>last three photos</strong></em> and follow me on <a href="http://twitter.com/pinaldave" target="_blank">twitter </a>(of course!)</p>
<p style="text-align:justify;">I have previously documented my four-day experience of SQL PASS 2009 Summit at Seattle. There were many reasons for SQL enthusiasts to attend the SQL PASS event; I am listing my own reasons here in order of importance to me.</p>
<ul style="text-align:justify;">
<li>Networking      with SQL fellows and experts</li>
<li>Putting      face to the name or avatar</li>
<li>Learning      and improving my SQL skills</li>
<li>Understanding      the structure of the largest SQL Server Professional Association</li>
<li>Attending      my favorite training sessions</li>
</ul>
<p style="text-align:justify;">During these four days, there was so much happening that it is difficult to document everything. I had tried to cover this event briefly on a daily basis in the following blog posts:</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/11/03/sqlauthority-news-sql-pass-summit-seattle-2009-day-1/" target="_blank">SQLAuthority News – SQL PASS Summit, Seattle 2009 – Day 1</a><br />
<a href="http://blog.sqlauthority.com/2009/11/04/sqlauthority-news-sql-pass-summit-seattle-2009-day-2/" target="_blank">SQLAuthority News – SQL PASS Summit, Seattle 2009 – Day 2</a><br />
<a href="http://blog.sqlauthority.com/2009/11/05/sqlauthority-news-sql-pass-summit-seattle-2009-day-3/" target="_blank">SQLAuthority News – SQL PASS Summit, Seattle 2009 – Day 3</a><br />
<a href="http://blog.sqlauthority.com/2009/11/06/sqlauthority-news-sql-pass-summit-seattle-2009-day-4/" target="_blank">SQLAuthority News – SQL PASS Summit, Seattle 2009 – Day 4</a></p>
<p style="text-align:justify;">I will list a few of the additional details that I have not included in the earlier post. Keynotes were the best part of the event, and I have covered major points of the keynote in above mentioned posts. I had met many SQL Legends during this event and included information regarding them. However, there were few things I still missed and I am listing them here. Seattle is great city, and I am visiting it the second time. This time I got an opportunity to take the Underground city tour and I had really enjoyed.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Washington Convention Center" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS514.jpg" alt="Washington Convention Center" width="500" height="666" /></dt>
<dd class="wp-caption-dd">Washington Convention Center</dd>
</dl>
</div>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Undergroud Tour 1" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS502.jpg" alt="Undergroud Tour 1" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Undergroud Tour 1</dd>
</dl>
</div>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Undergroup Tour 2" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS503.jpg" alt="Undergroup Tour 2" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Undergroup Tour 2</dd>
</dl>
</div>
<p style="text-align:justify;">It was great to meet SQL Server MVP Glenn Berry at the MVP Summit. He is a very kind and friendly person. You will always find him hanging around with people from different organizations and countries. If you try to eavesdrop his conversation, you will hear terms like &#8216;dmv&#8217;, &#8216;performance&#8217;, and &#8216;optimized query&#8217; very often. He is very much known for his excellent optimization script known as &#8220;<a href="http://glennberrysqlperformance.spaces.live.com/blog/cns%2145041418ECCAA960%212015.entry" target="_blank"><strong><em>SQL Server 2008 Diagnostic Information Queries</em></strong></a>&#8220;. If you have never taken a look at that, I urge you to go there and check this out. I believe that even if he blogs once a year only with this script, his fans will not complain. I have previously published his <a href="http://blog.sqlauthority.com/2009/08/09/sqlauthority-news-interview-with-sql-server-mvp-glenn-berry/" target="_blank"><strong>interview on my blog</strong></a>. Please note that he is the only person ever featured in an interview on this blog.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Glenn Berry and Pinal Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS505.jpg" alt="Glenn Berry and Pinal Dave" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Glenn Berry and Pinal Dave</dd>
</dl>
</div>
<p style="text-align:justify;"><strong><em>It depends!</em></strong> This is one most loved (or hated) phrase in the world of programmers or DBA. It is quite common to start answering question using this phrase. Mostly, this phrase initiates humor but rarely, people take this as offence. Again the intent of speaker is not always conveyed properly, <strong><em>it depends</em></strong> on how the phrase is used (I could not resist to use this phrase as well <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ). I had very interesting discussion with <a href="http://sqlfool.com/" target="_blank">Michelle Ufford</a> and <a href="http://stratesql.com/" target="_blank">Jason Strate</a> when we were waiting for coffee at one afternoon. We discussed both the sides of this phrase. Michelle suggested many good points when and why this phrase is valid. Jason also suggested that this phrase is commonly used a) when the presenter does not have sufficient information to answer or b) when the presenter does not know the answer. We discussed that it would be really interesting to start the conversation answering the most possible answer and then talking about special cases (for which <strong><em>it depends</em></strong> is quite commonly used.) Let us see one example.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Michelle Ufford, Jason Strate, Pinal Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS508.jpg" alt="Michelle Ufford, Jason Strate, Pinal Dave" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Michelle Ufford, Jason Strate, Pinal Dave</dd>
</dl>
</div>
<p style="text-align:justify;">Q: Does index improve performance?<br />
A1: It depends on query and data you have.<br />
A2: Usually YES; however, there are cases when it reduces performance, for which the query and data needs to be examined carefully.</p>
<p style="text-align:justify;">There are times when <strong><em>it depends</em></strong> totally make sense. I use it several times; I love the blog of Andy Warren which talks is branded as it depends. This discussion between three of us was just a friendly discussion, and if you think we are talking about you, it is wrong!</p>
<p style="text-align:justify;">During this event, I had great conversation with SQL Legend <a href="http://blogs.msdn.com/buckwoody/" target="_blank">Buck Woody</a>. This man is full of energy and may be the most loved person in this summit. His session was the funniest session I have ever attended. At the end of his session, I had more than 2 pages of my notebook filled with notes. If I have wrote down how many times, I have laughed loudly, I would have no time to do anything else. Buck had a good hour of discussion with me. We discussed many different topics, ranging from Community to Microsoft and Collage Students to SQL. I am very thankful to Buck for spending his valuable time with me – I am honored.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Buck Woody and Pinal Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS504.jpg" alt="Buck Woody and Pinal Dave" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Buck Woody and Pinal Dave</dd>
</dl>
</div>
<p style="text-align:justify;"><strong>Joe Celko</strong> – this name is very popular in SQL world, and I admit that I was always afraid of him. Every time I see his photo, I just felt nervous. I never thought that I should meet him. Honestly, for the same reason, I did not attend his session. <em><strong>I was absolutely wrong. </strong></em>I met him right after his session was over. He is one of the most friendly people I have met in my life. He is very soft spoken. He gauges the level and understanding of other person and speaks at the same level. He made me laugh and taught many good techniques for how to become good speaker and presenter. When I said I was sorry that I was scared of him, he laughed and said that he knows this. Boy, what a mistake I did!! I should have attended his session. Well, at least I am accepting my mistake here. He is indeed a very friendly soul. He promised me that one time he will come to India.</p>
<p style="text-align:justify;"><strong>Brian Moran</strong> is the newly elected board member; I would like to call him as &#8216;<strong><em>the Man with 1000 successful ideas</em></strong>&#8216;. You have to come across him to know what I am talking about. I had the great opportunity to meet him and discuss few things, besides SQL. Brian had many excellent ideas about how to build the community, how to help SQL PASS and few excellent ideas about how to take PASS to the next level. I am glad that he is one of the board members for PASS. PASS is all about passion, and Brian clearly demonstrates the same.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img class="  " title="Pinal Dave, Joe Celko, Brian Moran" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS515.jpg" alt="Pinal Dave, Joe Celko, Brian Moran" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Pinal Dave, Joe Celko, Brian Moran</dd>
</dl>
</div>
<p style="text-align:justify;">I met all of them and had a great conversation with them. It was great to meet <strong>Ed Hackney</strong>; he is a wonderful person and very easily approachable. He talked about SQL community in India and how any community cannot be restrained within geographical boundaries.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Ed Hackney and Pinal Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS509.jpg" alt="Ed Hackney and Pinal Dave" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Ed Hackney and Pinal Dave</dd>
</dl>
</div>
<p style="text-align:justify;">I was waiting to meet <a href="http://thomaslarock.com/" target="_blank">Thomas LaRock</a>. He is an excellent SQL Master, and he talked in detail about outsourcing SQL technology and SQL community. I really enjoyed meeting him and spending some time with him during the summit. I plan to learn more from him when I meet him next time.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Thomas LaRock and Pinal Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS513.jpg" alt="Thomas LaRock and Pinal Dave" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Thomas LaRock and Pinal Dave</dd>
</dl>
</div>
<p style="text-align:justify;"><a href="http://arcanecode.com/" target="_blank">Robert Cain</a>, he is one of the very few SQL masters, who have expertise in .net and Business Intelligence at the same time. I have previously wrote about him in <a href="http://blog.sqlauthority.com/2009/07/12/sqlauthority-news-big-thinkers-robert-cain/" target="_blank"><strong>Big Thinkers – Robert Cain</strong></a>. He has given approval that I can write about his BI presentation on this blog. I will write about it soon.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img class=" " title="Chris Massey, Robert Cain, Pinal Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS517.jpg" alt="Chris Massy, Robert Cain, Pinal Dave" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Chris Massey, Robert Cain, Pinal Dave</dd>
</dl>
</div>
<p style="text-align:justify;">I have previously written a lot about Greg Low on this blog. However, I just can not resist to put this excellent photo once again here. He has great respect for the international community; and he had spent some quality time with me discussing how to enhance and grow the global community. Greg gave his insight and few plan cache tips as well. You can read my review of his book &#8216;<a href="http://blog.sqlauthority.com/2009/07/03/sqlauthority-news-book-review-the-rational-guide-to-building-technical-user-communities-rational-guides/" target="_blank">Book Review – The Rational Guide to Building Technical User Communities (Rational Guides)</a>&#8216;. You can also read our discussion on plan cache &#8216;<a href="http://blog.sqlauthority.com/2009/09/14/sql-server-plan-caching-and-schema-change-an-interesting-observation/" target="_blank">SQL SERVER – Plan Caching and Schema Change – An Interesting Observation</a>&#8216;.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Greg Low and Pinal Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS510.jpg" alt="Greg Low and Pinal Dave" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Greg Low and Pinal Dave</dd>
</dl>
</div>
<p style="text-align:justify;">Following image is for sure very interesting! Can you recognize the person? Well, just <a href="http://itknowledgeexchange.techtarget.com/sql-server/sharp-sqlpass-hair-color-voting-ends-tonight-cast-your-vote-before-its-too-late/" target="_blank">go here</a> and read about <a href="http://itknowledgeexchange.techtarget.com/sql-server/" target="_blank">Mr. Denny</a>. And I do have permission from him to publish this photo!</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Mr. Danny" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS511.jpg" alt="Mr. Danny" width="500" height="666" /></dt>
<dd class="wp-caption-dd">Mr. Danny</dd>
</dl>
</div>
<p style="text-align:justify;">PASS 2010 dates are announced; this event will take place between 8 and 12 November 2010.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="PASS 2010" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS507.jpg" alt="PASS 2010" width="500" height="375" /></dt>
<dd class="wp-caption-dd">PASS 2010</dd>
</dl>
</div>
<p style="text-align:justify;">Following image is my favorite as it brings the future and past of PASS together. Kevin Kline, a hero of PASS summit, (as he dedicated 10 years of his life to serve PASS board) is in same frame with Rushabh Mehta, who is President Elect for 2010.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img class=" " title="Past President Kevin Kline and Future President Rushabh Mehta" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS506.jpg" alt="Past President Kevin Kline and Future President Rushabh Mehta" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Past President Kevin Kline and Future President Rushabh Mehta</dd>
</dl>
</div>
<p style="text-align:justify;">Now I am coming to the most interesting part of my experience. I want to introduce to all of you the youngest SQL PASS fan and follower. Her name is <a href="http://blog.sqlauthority.com/2009/09/08/sqlauthority-news-shaivi-dave-baby-sqlauthority/" target="_blank"><strong>Shaivi Dave</strong></a>, and she is big fan of SQL PASS! Shaivi suggests that save your money and register right away for PASS. There is no other conference which is as valuable as SQL PASS.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Nupur Dave and Shaivi Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS501.jpg" alt="Nupur Dave and Shaivi Dave" width="500" height="666" /></dt>
<dd class="wp-caption-dd">Nupur Dave and Shaivi Dave</dd>
</dl>
</div>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Pinal Dave and Shaivi Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/SQLPASS500.jpg" alt="Pinal Dave and Shaivi Dave" width="500" height="666" /></dt>
<dd class="wp-caption-dd">Pinal Dave and Shaivi Dave</dd>
</dl>
</div>
<p style="text-align:justify;">She had conveyed her wish to SQL PASS President Elect Rushabh Mehta when she was just 19 days old. May be one of following years, we will see her at summit.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="Rushabh Mehta, Shaivi Dave, Pinal Dave" src="http://www.pinaldave.com/bimg/sqlpass2009/Rushabh_Shaivi_Pinal.jpg" alt="Rushabh Mehta, Shaivi Dave, Pinal Dave" width="500" height="375" /></dt>
<dd class="wp-caption-dd">Rushabh Mehta, Shaivi Dave, Pinal Dave</dd>
</dl>
</div>
<p style="text-align:justify;">This is note is addendum to my four original posts. I strongly suggest you all to read my earlier posts for details on keynote and other SQL legends.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/11/03/sqlauthority-news-sql-pass-summit-seattle-2009-day-1/" target="_blank">SQLAuthority News – SQL PASS Summit, Seattle 2009 – Day 1</a><br />
<a href="http://blog.sqlauthority.com/2009/11/04/sqlauthority-news-sql-pass-summit-seattle-2009-day-2/" target="_blank">SQLAuthority News – SQL PASS Summit, Seattle 2009 – Day 2</a><br />
<a href="http://blog.sqlauthority.com/2009/11/05/sqlauthority-news-sql-pass-summit-seattle-2009-day-3/" target="_blank">SQLAuthority News – SQL PASS Summit, Seattle 2009 – Day 3</a><br />
<a href="http://blog.sqlauthority.com/2009/11/06/sqlauthority-news-sql-pass-summit-seattle-2009-day-4/" target="_blank">SQLAuthority News – SQL PASS Summit, Seattle 2009 – Day 4</a></p>
<p style="text-align:justify;">If you have visited this event and have something more to add to what I have written, please feel free to add it here as a comment. I am looking forward for you all to add more details and information here. <strong><a href="http://twitter.com/pinaldave" target="_blank">Follow me on twitter</a></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>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;text-align:justify;"><span id="ctl00_MainContentPlaceholder_ctl01_ctl00_lblEntry"> </span></p>
<h4 id="subjcns!45041418ECCAA960!2015" class="beTitle">SQL Server 2008 Diagnostic Information Queries</h4>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to enforce a foreign key constraint against multiple tables]]></title>
<link>http://whileicompile.wordpress.com/2009/11/09/how-to-enforce-a-foreign-key-constraint-against-multiple-tables/</link>
<pubDate>Mon, 09 Nov 2009 14:30:40 +0000</pubDate>
<dc:creator>John MacIntyre</dc:creator>
<guid>http://whileicompile.wordpress.com/2009/11/09/how-to-enforce-a-foreign-key-constraint-against-multiple-tables/</guid>
<description><![CDATA[I am building a web app with Ben Alabaster, and one of the requirements is for the user to be able t]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I am building a web app with Ben Alabaster, and one of the requirements is for the user to be able to flag items for moderators. So the user can flag entity A, entity B, entity C, etc…</p>
<p>So I created a single flag table.</p>
<div id="attachment_229" class="wp-caption alignnone" style="width: 300px"><a href="http://whileicompile.wordpress.com/files/2009/11/091107-flagtable.png"><img class="size-full wp-image-229 " title="Flag Table" src="http://whileicompile.wordpress.com/files/2009/11/091107-flagtable.png" alt="Flag Table" width="290" height="171" /></a><p class="wp-caption-text">Flag Table</p></div>
<p>Which I then tried to tie it to the entity tables, hoping for something like</p>
<div id="attachment_231" class="wp-caption alignnone" style="width: 460px"><a href="http://whileicompile.wordpress.com/files/2009/11/091107-idealfkrelationships.png"><img class="size-full wp-image-231 " title="Ideal FK Relationships" src="http://whileicompile.wordpress.com/files/2009/11/091107-idealfkrelationships.png" alt="Ideal Foriegn Key Relationships" width="450" height="218" /></a><p class="wp-caption-text">Ideal Foriegn Key Relationships</p></div>
<p>Where all the foreign key relationships were from [flag].[entity_id] to [EntityX].[id]</p>
<p>Then when I wanted the top 10 flags from a particular entity (B in this case), I could run a query like</p>
<div style="background-color:beige;text-align:left;margin:0;padding:.2em;"><code>select top 20 e.[name], count(*) "count"<br />
from entityB as e<br />
&#160;&#160;&#160;left join flag as f<br />
&#160;&#160;&#160;&#160;on f.entity_id = e.id<br />
where f.entity_type='B'<br />
group by e.[name]<br />
order by count(*) desc</code></div>
<p>Unfortunately, if you were to create the above table relationship, and run the following inserts</p>
<div style="background-color:beige;text-align:left;margin:0;padding:.2em;"><code>insert into EntityA( id, name) values (1, 'EntityA');<br />
insert into EntityB( id, name) values (2, 'EntityB');<br />
insert into EntityC( id, name) values (3, 'EntityC');<br />
insert into EntityD( id, name) values (4, 'EntityD');</code></div>
<p>The following statement</p>
<div style="background-color:beige;text-align:left;margin:0;padding:.2em;"><code>insert into flag(entity_id, flag_reason) values(5, 'Testing without a valid FK value.');</code></div>
<p>would fail as expected, as expected, with the following error. “The INSERT statement conflicted with the FOREIGN KEY constraint &#8220;FK_flag_EntityA&#8221;. The conflict occurred in database &#8220;test&#8221;, table &#8220;dbo.EntityA&#8221;, column &#8216;id&#8217;.”</p>
<p>But</p>
<div style="background-color:beige;text-align:left;margin:0;padding:.2em;"><code>insert into flag(entity_id, flag_reason) values(1, 'Testing the FK to entity A.');</code></div>
<p>would also fail, which was undesired, with the following error: “The INSERT statement conflicted with the FOREIGN KEY constraint &#8220;FK_flag_EntityB&#8221;. The conflict occurred in database &#8220;test&#8221;, table &#8220;dbo.EntityB&#8221;, column &#8216;id&#8217;.” +</p>
<p>So, my options with regards to referential integrity are :</p>
<ol>
<li>Ditch the referential integrity, which I am vehemently opposed to. ++</li>
<li>Create multiple flag tables, each with the exact same schema, but a different Foreign Key relationship, which just seems wrong.</li>
<li>Managing referential integrity via triggers.</li>
</ol>
<p>While I’m not a big fan of triggers, the ‘Managing referential integrity via triggers.’ option seems like the only tolerable one. So I added the [entity_type] column to my flag table.</p>
<div id="attachment_230" class="wp-caption alignnone" style="width: 300px"><a href="http://whileicompile.wordpress.com/files/2009/11/091107-flagtablewithentitytype.png"><img class="size-full wp-image-230 " title="Flag Table With Entity Type" src="http://whileicompile.wordpress.com/files/2009/11/091107-flagtablewithentitytype.png" alt="Flag Table With Entity Type" width="290" height="200" /></a><p class="wp-caption-text">Flag Table With Entity Type</p></div>
<p>Removed the relationships</p>
<div id="attachment_228" class="wp-caption alignnone" style="width: 460px"><a href="http://whileicompile.wordpress.com/files/2009/11/091107-norelationships.png"><img class="size-full wp-image-228 " title="No Relationships" src="http://whileicompile.wordpress.com/files/2009/11/091107-norelationships.png" alt="No Relationships" width="450" height="219" /></a><p class="wp-caption-text">No Relationships</p></div>
<p>And wrote the following trigger to manage the foreign key relationship.</p>
<div style="background-color:beige;text-align:left;margin:0;padding:.2em;"><code>-- =============================================<br />
-- Description: maintain referential integrity on<br />
-- a column which is a FK for different tables<br />
-- =============================================<br />
CREATE TRIGGER flag_entity_id_fk<br />
ON flag<br />
AFTER INSERT,UPDATE<br />
AS<br />
BEGIN<br />
declare @entity_type char(1);<br />
declare @entity_id int;<br />
declare @cnt int;</p>
<p>&#160;-- SET NOCOUNT ON added to prevent extra result sets from<br />
&#160;-- interfering with SELECT statements.<br />
&#160;SET NOCOUNT ON;</p>
<p>&#160;-- get info<br />
&#160;select @entity_type=entity_type,<br />
&#160;&#160;&#160;@entity_id=entity_id,<br />
&#160;&#160;&#160;@cnt=0<br />
&#160;from inserted;<br />
&#160;<br />
&#160;-- check if records exist<br />
&#160;if 'A' = @entity_type<br />
&#160;begin<br />
&#160;&#160;select @cnt=count(*)<br />
&#160;&#160;from entityA<br />
&#160;&#160;where id=@entity_id;<br />
&#160;end<br />
&#160;else if 'B' = @entity_type<br />
&#160;begin<br />
&#160;&#160;select @cnt=count(*)<br />
&#160;&#160;from entityB<br />
&#160;&#160;where id=@entity_id;<br />
&#160;end<br />
&#160;else if 'C' = @entity_type<br />
&#160;begin<br />
&#160;&#160;select @cnt=count(*)<br />
&#160;&#160;from entityC<br />
&#160;&#160;where id=@entity_id;<br />
&#160;end<br />
&#160;else if 'D' = @entity_type<br />
&#160;begin<br />
&#160;&#160;select @cnt=count(*)<br />
&#160;&#160;from entityD<br />
&#160;&#160;where id=@entity_id;<br />
&#160;end</p>
<p>&#160;-- records exist? exit<br />
&#160;if 0 &#60; @cnt<br />
&#160;begin<br />
&#160;&#160;return;<br />
&#160;end</p>
<p>&#160;-- no? error<br />
&#160;raiserror( 'Unable to find foriegn key match on entity type ''%s'', id ''%d''.', 16, 1, @entity_type, @entity_id);<br />
&#160;rollback transaction;<br />
END</code></div>
<p>Now, when you run</p>
<div style="background-color:beige;text-align:left;margin:0;padding:.2em;"><code>insert into flag(entity_type, entity_id, flag_reason) values('B', 5, 'Testing without a valid FK value.');</code></div>
<p>The trigger doesn’t find a match in the appropriate table, rolls back the insert, and gives you a descriptive error message.</p>
<blockquote><p>Unable to find foriegn key match on entity type &#8216;B&#8217;, id &#8216;5&#8242;.</p></blockquote>
<p>However, a good value is accepted.</p>
<div style="background-color:beige;text-align:left;margin:0;padding:.2em;"><code>insert into flag(entity_type, entity_id, flag_reason) values('B', 2, 'Testing without a valid FK value.');</code></div>
<p>I’m still not happy with this approach, but it does seem to be the lesser of all the evils. Please let me know with a comment if there is another option I’ve overlooked. Thanks.</p>
<p>* <em>Frankly I was surprised it even compiled.</em><br />
+ <em>Unless of course you were unfortunate enough to test this in a coincidental situation where all tables happened to contain the id of every test you ran.</em><br />
++ <em>Yes ‘vehemently’</em></p>
<p>EDIT (11/10/2009) : It just occurred to me that this article does not take into account what would happen if the entity tables were to delete a row which this table was pointing to.  When I designed my tables this was taken into account, but since we are not planning to allow actual deletions, it was left out.  However, if you were to implement this strategy, where entities could be deleted, a delete trigger would need to be created for each entity table.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - System Stored Procedure Script]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/09/sql-server-system-stored-procedure-script/</link>
<pubDate>Mon, 09 Nov 2009 05:30:24 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/09/sql-server-system-stored-procedure-script/</guid>
<description><![CDATA[System Stored Procedure Script Have you seen script of System Stored Procedure of SQL Server? Well i]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>System Stored Procedure Script</strong></p>
<p>Have you seen script of System Stored Procedure of SQL Server? Well if you are curious creature like me, then why not see it.</p>
<p>To do that, we need to use another <strong>System Stored Procedure</strong><span style="color:#800000;"> sp_helptext</span>. It will display the script behind the specified System Stored Procedure.</p>
<p><strong>Syntax:</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">EXEC</span> <span style="color:#800000;">sp_helptext</span> <span style="color:#ff0000;">&#8216;System Stored Procedure&#8217;</span></p>
</div>
<p><strong>Example:</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">- &#8211; To see the script of sp_helplogins</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">EXEC</span> <span style="color:#800000;">sp_helptext</span> <span style="color:#ff0000;">&#8216;master..sp_helplogins&#8217;</span></p>
</div>
<p>Go ahead and try it with other System Stored Procedures.</p>
<p>Did you see how Microsoft codes their Stored Procedures? If you think &#8220;<strong>Even I can do this stuff</strong>&#8220;, feel luck and please forward your resume to <strong>Microsoft Corporation</strong>! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - SERVERPROPERTY Function]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/07/sql-server-serverproperty-function/</link>
<pubDate>Sat, 07 Nov 2009 05:48:33 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/07/sql-server-serverproperty-function/</guid>
<description><![CDATA[SERVERPROPERTY Function How does one get list all Server Properties? Well, we can use a very helpful]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>SERVERPROPERTY Function</strong></p>
<p>How does one get list all Server Properties? Well, we can use a very helpful system function <span style="color:#ff00ff;">SERVERPROPERTY</span>. It will return information about the server instance for a specified property.</p>
<p><strong>Syntax:</strong></p>
<p style="padding-left:30px;"><span style="color:#ff00ff;">SERVERPROPERTY</span> (propertyname)</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>I have kept the following script in my archives, you may do the same.</p>
<p><strong> </strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;margin:20px 0 30px;padding:4px;"><span style="color:#008000;">&#8211; Returns all the property information about the server instance</span>
<p>&#160;</p>
<p><span style="color:#0000ff;"> SELECT</span><span style="color:#ff0000;"> &#8216;BuildClrVersion&#8217;</span><span style="color:#0000ff;"> AS</span> &#8216;Server Property&#8217;, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;BuildClrVersion&#8217;</span>) <span style="color:#0000ff;">AS</span> &#8216;Value&#8217;</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;Collation&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;Collation&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;CollationID&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;CollationID&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;ComparisonStyle&#8217;</span>,<span style="color:#ff00ff;"> SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;ComparisonStyle&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;ComputerNamePhysicalNetBIOS&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;ComputerNamePhysicalNetBIOS&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;Edition&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;Edition&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;EditionID&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;EditionID&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;EngineEdition&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;EngineEdition&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;InstanceName&#8217;</span>,<span style="color:#ff00ff;"> SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;InstanceName&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;IsClustered&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;IsClustered&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;IsFullTextInstalled&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;IsFullTextInstalled&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;IsIntegratedSecurityOnly&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;IsIntegratedSecurityOnly&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;IsSingleUser&#8217;</span>,<span style="color:#ff00ff;"> SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;IsSingleUser&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;LCID&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;LCID&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;LicenseType&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;LicenseType&#8217;</span>)</p>
<p style="text-align:justify;padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;MachineName&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;MachineName&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;NumLicenses&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;NumLicenses&#8217;</span>)</p>
<p style="padding-left:30px;">UNION ALL</p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;ProcessID&#8217;</span>,<span style="color:#ff00ff;"> SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;ProcessID&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;ProductVersion&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;ProductVersion&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;ProductLevel&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;ProductLevel&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;ResourceLastUpdateDateTime&#8217;</span>,<span style="color:#ff00ff;"> SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;ResourceLastUpdateDateTime&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;ResourceVersion&#8217;</span>,<span style="color:#ff00ff;"> SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;ResourceVersion&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;ServerName&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;ServerName&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;SqlCharSet&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;SqlCharSet&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT </span><span style="color:#ff0000;">&#8216;SqlCharSetName&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;SqlCharSetName&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;SqlSortOrder&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;SqlSortOrder&#8217;</span>)</p>
<p style="text-align:justify;padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;SqlSortOrderName&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;SqlSortOrderName&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span> <span style="color:#ff0000;">&#8216;FilestreamShareName&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;FilestreamShareName&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;FilestreamConfiguredLevel&#8217;</span>,<span style="color:#ff00ff;"> SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;FilestreamConfiguredLevel&#8217;</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">UNION ALL</span></p>
<p><span style="color:#0000ff;">SELECT</span><span style="color:#ff0000;"> &#8216;FilestreamEffectiveLevel&#8217;</span>, <span style="color:#ff00ff;">SERVERPROPERTY</span>(<span style="color:#ff0000;">&#8216;FilestreamEffectiveLevel&#8217;</span>)</p>
</div>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>If you want to check what all these different <strong>Server Property</strong> means, please also see <a href="http://msdn.microsoft.com/en-us/library/ms174396.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms174396.aspx</a></p>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[MS SqlServer Row Value Concatenation]]></title>
<link>http://devblog.point2.com/2009/11/06/ms-sqlserver-row-value-concatenation/</link>
<pubDate>Fri, 06 Nov 2009 22:55:31 +0000</pubDate>
<dc:creator>Jesse Webb</dc:creator>
<guid>http://devblog.point2.com/2009/11/06/ms-sqlserver-row-value-concatenation/</guid>
<description><![CDATA[Recently, a colleague and I found ourselves in the situation of needing to concatenate values from m]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Recently, a colleague and I found ourselves in the situation of needing to concatenate values from multiple rows of a MS SqlServer database table. We were trying to form a comma-delimited list of phone numbers for every customer in our database. One customer may have many phone numbers. Here is a simplified diagram visualizing the relationship between customer and phone numbers:</p>
<div id="attachment_1038" class="wp-caption aligncenter" style="width: 335px"><img class="size-full wp-image-1038" title="customer_phonenumber" src="http://point2blog.wordpress.com/files/2009/11/customer_phonenumber1.png" alt="customer_phonenumber" width="325" height="105" /><p class="wp-caption-text">Customer - Phone Number Relationship</p></div>
<p>The format of data we were looking for was:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="319" valign="top">CustomerId</td>
<td width="319" valign="top">PhoneNumbers</td>
</tr>
<tr>
<td width="319" valign="top">1</td>
<td width="319" valign="top">“(306) 555-1111”, “555-2222”, “306-555-3333”</td>
</tr>
<tr>
<td width="319" valign="top">2</td>
<td width="319" valign="top">“3065554444”</td>
</tr>
</tbody>
</table>
<p>We tried various queries to perform the concatenation correctly but none of our <em>solutions</em> seemed to do the job perfectly; either the final &#8216;PhoneNumbers&#8217; string would have an additional comma at the end or some other undesired effect. We finally came across an article explaining in great detail of how to use TSQL (the SQL engine behind SqlServer) to perform the operations we needed.</p>
<p>http://www.projectdmx.com/tsql/rowconcatenate.aspx</p>
<p>This article has various examples describing AND explaining how to do multiple row value concatenations such as explicit examples for &#8220;Concatenating values when the number of items is small and known upfront&#8221; and &#8220;Concatenating values when the number of items is not known&#8221;. The author even walks through a recursive solution or two.</p>
<p>We determined that we knew none of our customers had more than five phone numbers based on the fact that they were limited to the PhoneType enumeration which only has five values. This allowed us to use the articles first example to get our job done efficiently. Here is our final solution:</p>
<pre>SELECT CustomertId, REPLACE(
 '"' + MAX( CASE seq WHEN 1 THEN phoneNumber ELSE '' END ) + '",' +
 '"' + MAX( CASE seq WHEN 2 THEN phoneNumber ELSE '' END ) + '",' +
 '"' + MAX( CASE seq WHEN 3 THEN phoneNumber ELSE '' END ) + '",' +
 '"' + MAX( CASE seq WHEN 4 THEN phoneNumber ELSE '' END ) + '",' +
 '"' + MAX( CASE seq WHEN 5 THEN phoneNumber ELSE '' END ) + '"', ',""', '' ) as PhoneNumbers
FROM (
 SELECT pn1.CustomerId, pn1.PhoneNumber, (
 SELECT COUNT(*)
 FROM PhoneNumber pn2
 WHERE pn2.CustomerId = pn1.CustomerId
 AND pn2.phoneNumber &#60;= pn1.phoneNumber)
 FROM PhoneNumber pn1) PhoneNumbersPerParty ( CustomerId, phoneNumber, seq )
GROUP BY CustomerId
By: <a href="http://devblog.point2.com/author/jessewebb/" target="_blank">Jesse Webb</a></pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Find an object using system tables]]></title>
<link>http://sqlweblog.wordpress.com/2009/11/05/find-an-object-using-system-tables/</link>
<pubDate>Thu, 05 Nov 2009 17:46:24 +0000</pubDate>
<dc:creator>SQLWebLogger</dc:creator>
<guid>http://sqlweblog.wordpress.com/2009/11/05/find-an-object-using-system-tables/</guid>
<description><![CDATA[&#160; Oracle sql server system tables all_objects OR user_catalog, all_catalog, dba_catalog sys.obj]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><table border="1" cellspacing="0" cellpadding="2" width="800">
<tbody>
<tr>
<td valign="top" width="292">&#160;</td>
<td valign="top" width="240">Oracle</td>
<td valign="top" width="266">sql server</td>
</tr>
<tr>
<td valign="top" width="292">system tables</td>
<td valign="top" width="240">all_objects OR         <br />user_catalog, all_catalog, dba_catalog</td>
<td valign="top" width="266">sys.objects OR          <br />information_schema.tables           <br />information_schema.Routines</td>
</tr>
<tr>
<td valign="top" width="292">example: Returning all rows with the object name that contains the word ORDERS</td>
<td valign="top" width="240">
<p>SELECT *            <br />FROM all_objects             <br />WHERE rownum&#60;100            <br />AND object_name LIKE &#8216;%ORDERS%&#8217;;</p>
</td>
<td valign="top" width="266">
<p>USE &#60;database_name&#62;;            <br />GO             <br />SELECT *             <br />FROM sys.objects             <br />WHERE name like ‘%ORDERS%’</p>
</td>
</tr>
<tr>
<td valign="top" width="292">further reading</td>
<td valign="top" width="240"><a title="http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76961/ch25.htm#795" href="http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76961/ch25.htm#795">http://download-west.oracle.com/docs/cd/A87860_01/doc/            <br />server.817/a76961/ch25.htm#795</a>           </td>
<td valign="top" width="266"><a title="http://msdn.microsoft.com/en-us/library/ms190324.aspx" href="http://msdn.microsoft.com/en-us/library/ms190324.aspx">http://msdn.microsoft.com/en-us/library/ms190324.aspx</a></td>
</tr>
</tbody>
</table>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Object dependencies]]></title>
<link>http://sqlweblog.wordpress.com/2009/11/05/object-dependencies/</link>
<pubDate>Thu, 05 Nov 2009 16:54:00 +0000</pubDate>
<dc:creator>SQLWebLogger</dc:creator>
<guid>http://sqlweblog.wordpress.com/2009/11/05/object-dependencies/</guid>
<description><![CDATA[&#160; Oracle SQL Server system tables USER_DEPENDENCIES or ALL_DEPENDENCIES or DBA_DEPENDENCIES sys]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><table border="1" cellspacing="0" cellpadding="2" width="871">
<tbody>
<tr>
<td valign="top" width="98">&#160;</td>
<td valign="top" width="412">Oracle </td>
<td valign="top" width="359">SQL Server</td>
</tr>
<tr>
<td valign="top" width="98">system tables</td>
<td valign="top" width="414">
<p>USER_DEPENDENCIES or            <br />ALL_DEPENDENCIES or             <br />DBA_DEPENDENCIES</p>
</td>
<td valign="top" width="358">sys.sysdepends(2000)          <br />sys.sql_dependencies(2005)           <br />sys.sql_expression_dependencies(2008)</td>
</tr>
<tr>
<td valign="top" width="98">procedure</td>
<td valign="top" width="415">&#160;</td>
<td valign="top" width="358"><b>sp_depends</b> [ <b>@objname =</b> ] <b>&#8216;</b>&#60;object&#62;<b>&#8216;</b></td>
</tr>
<tr>
<td valign="top" width="98">&#160;</td>
<td valign="top" width="415">
<p>SELECT&#160; <br />&#160; OWNER&#124;&#124;&#8217;.'&#124;&#124;NAME,             <br />&#160; TYPE             <br />FROM             <br />&#160; dba_dependencies             <br />WHERE&#160; <br />REFERENCED_NAME LIKE &#8216;ObjectName&#8217; &#8211;CaseSensitive             <br />ORDER BY             <br />&#160; TYPE;</p>
</td>
<td valign="top" width="358">
<p>USE AdventureWorks            <br />GO             <br />EXEC sp_depends             <br />&#160; @objname = N&#8217;Sales.Customer&#8217;;</p>
</td>
</tr>
<tr>
<td valign="top" width="98">further reading</td>
<td valign="top" width="416"><a title="http://www.orafaq.com/node/807" href="http://www.orafaq.com/node/807">http://www.orafaq.com/node/807</a>           <br /><a title="http://wiki.oracle.com/page/Determine+Object+Dependencies" href="http://wiki.oracle.com/page/Determine+Object+Dependencies">http://wiki.oracle.com/page/Determine+Object+Dependencies</a></td>
<td valign="top" width="369"><a title="http://msdn.microsoft.com/en-us/library/ms345449.aspx" href="http://msdn.microsoft.com/en-us/library/ms345449.aspx">http://msdn.microsoft.com/en-us/library/ms345449.aspx</a><a title="http://msdn.microsoft.com/en-us/library/ms174402(SQL.90).aspx" href="http://msdn.microsoft.com/en-us/library/ms174402(SQL.90).aspx">            <br />http://msdn.microsoft.com/en-us/library/ms174402(SQL.90).aspx</a>           <br /><a title="http://www.mssqltips.com/tip.asp?tip=1294" href="http://www.mssqltips.com/tip.asp?tip=1294">http://www.mssqltips.com/tip.asp?tip=1294</a></td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>For SQL Server, <u>sp_depends</u> is the recommended method, as the supporting system tables will be automatically selected based on the version. </p>
<p>In Oracle, the string operations are case sensitive. so before you start smashing your head to the desk, change the case and try to find the objects.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - List all Foreign Key Constraints of Database or Table]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-list-all-foreign-key-constraints-of-database-or-table/</link>
<pubDate>Thu, 05 Nov 2009 09:15:39 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-list-all-foreign-key-constraints-of-database-or-table/</guid>
<description><![CDATA[List all Foreign Key Constraints of Database or Table How often we face this problem? The Foreign Ke]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>List all Foreign Key Constraints of Database or Table</strong></p>
<p>How often we face this problem? The <strong>Foreign Key</strong> constraint of the table preventing us from deleting or modifying records.</p>
<p>To deal with them, first we need to have information about these constraints. How nice it would it be to get details of all the Foreign Key constraint defined in the <strong>Database</strong> or on a <strong>Table.</strong></p>
<p><strong> </strong>Good<strong> </strong>News, yes we can. Just use following script:</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:800px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE</span> AdventureWorks</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; List all Foreign Key Constraints in whole Database</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> o1.name <span style="color:#0000ff;">AS</span> Referencing_Object_name,</p>
<p style="padding-left:90px;">c1.name <span style="color:#0000ff;">AS</span> referencing_column_Name,</p>
<p style="padding-left:90px;">o2.name <span style="color:#0000ff;">AS</span> Referenced_Object_name,</p>
<p style="padding-left:90px;">c2.name <span style="color:#0000ff;">AS </span>Referenced_Column_Name,</p>
<p style="padding-left:90px;">s.name <span style="color:#0000ff;">AS</span> Constraint_name</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">FROM</span> sysforeignkeys fk</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> sysobjects o1<span style="color:#0000ff;"> ON</span> fk.fkeyid = o1.id</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> sysobjects o2 <span style="color:#0000ff;">ON</span> fk.rkeyid = o2.id</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> syscolumns c1 <span style="color:#0000ff;">ON</span> c1.id = o1.id <span style="color:#0000ff;">AND</span> c1.colid = fk.fkey</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> syscolumns c2<span style="color:#0000ff;"> ON</span> c2.id = o2.id<span style="color:#0000ff;"> AND</span> c2.colid = fk.rkey</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> sysobjects s <span style="color:#0000ff;">ON </span>fk.constid = s.id</p>
<p style="padding-left:30px;"><span style="color:#008000;"><br />
</span></p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; List all Foreign Key Constraints in Table Customer</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT </span> o1.name <span style="color:#0000ff;">AS </span>Referencing_Object_name,</p>
<p style="padding-left:90px;">c1.name <span style="color:#0000ff;">AS</span> referencing_column_Name,</p>
<p style="padding-left:90px;">o2.name <span style="color:#0000ff;">AS</span> Referenced_Object_name,</p>
<p style="padding-left:90px;">c2.name <span style="color:#0000ff;">AS</span> Referenced_Column_Name,</p>
<p style="padding-left:90px;">s.name <span style="color:#0000ff;">AS </span>Constraint_name</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">FROM</span> sysforeignkeys fk</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> sysobjects o1<span style="color:#0000ff;"> ON</span> fk.fkeyid = o1.id</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> sysobjects o2 <span style="color:#0000ff;">ON</span> fk.rkeyid = o2.id</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> syscolumns c1 <span style="color:#0000ff;">ON</span> c1.id = o1.id <span style="color:#0000ff;">AND</span> c1.colid = fk.fkey</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> syscolumns c2 <span style="color:#0000ff;">ON</span> c2.id = o2.id <span style="color:#0000ff;">AND</span> c2.colid = fk.rkey</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">INNER JOIN</span> sysobjects s <span style="color:#0000ff;">ON</span> fk.constid = s.id</p>
<p style="padding-left:90px;"><span style="color:#0000ff;">AND</span> o2.name=<span style="color:#ff0000;">&#8216;Customer&#8217;</span></p>
<p style="padding-left:30px;">
</div>
<p><strong>See also:</strong></p>
<p><a href="http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-list-all-constraints-of-database-or-table/" target="_blank">SQL Server &#8211; List all Constraints of Database or Table</a></p>
<p><a href="http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-drop-all-table-constraints/" target="_blank">SQL Server &#8211; Drop All Table Constraints</a></p>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - Drop All Table Constraints]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-drop-all-table-constraints/</link>
<pubDate>Thu, 05 Nov 2009 09:07:37 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-drop-all-table-constraints/</guid>
<description><![CDATA[Drop All Table Constraints You want to redefine all the constraints set on a Table. To do that you n]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Drop All Table Constraints</strong></p>
<p>You want to redefine all the constraints set on a Table. To do that you need to first <strong>drop</strong> all the existing constraints set on the table. Following is the simple script to do so the same:</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:600px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; To drop all Constraints on a table Employee</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DECLARE</span> @database <span style="color:#0000ff;">NVARCHAR</span>(50)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DECLARE </span>@table <span style="color:#0000ff;">NVARCHAR</span>(50)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">DECLARE</span> @sql <span style="color:#0000ff;">NVARCHAR</span>(255)</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">SET</span> @database =<span style="color:#ff0000;"> &#8216;DB_MyDatabase&#8217;</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SET</span> @table = <span style="color:#ff0000;">&#8216;Employee&#8217;</span></p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">WHILE EXISTS </span>(<span style="color:#0000ff;">SELECT</span> * <span style="color:#0000ff;">FROM </span><span style="color:#008000;">INFORMATION_SCHEMA.TABLE_CONSTRAINTS</span></p>
<p style="padding-left:150px;"><span style="color:#0000ff;">WHERE</span> constraint_catalog=@database <span style="color:#0000ff;">AND</span> table_name=@table)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">BEGIN</span></p>
<p style="padding-left:60px;"><span style="color:#0000ff;">SELECT</span> @sql = <span style="color:#ff0000;">&#8216;ALTER TABLE &#8216; </span>+ @table +<span style="color:#ff0000;"> &#8216; DROP CONSTRAINT &#8216;</span> + CONSTRAINT_NAME</p>
<p style="padding-left:60px;"><span style="color:#0000ff;">FROM</span> <span style="color:#008000;"> INFORMATION_SCHEMA.TABLE_CONSTRAINTS</span></p>
<p style="padding-left:60px;"><span style="color:#0000ff;">WHERE</span> constraint_catalog=@database AND table_name=@table</p>
<p style="padding-left:60px;">
<p style="padding-left:60px;"><span style="color:#0000ff;">EXEC</span> <span style="color:#800000;">sp_executesql</span> @sql</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">END</span></p>
<p style="padding-left:30px;">
</div>
<p>The above script does not drop <span style="color:#0000ff;">DEFAULT</span> constraint set on the Table.</p>
<p><strong>See also:</strong></p>
<p><a href="http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-list-all-constraints-of-database-or-table/" target="_blank">SQL Server &#8211; List all Constraints of Database or Table</a></p>
<p><a href="http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-list-all-foreign-key-constraints-of-database-or-table/" target="_blank">SQL Server &#8211; List all Foreign Key Constraints of Database or Table</a></p>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - List all Constraints of Database or Table]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-list-all-constraints-of-database-or-table/</link>
<pubDate>Wed, 04 Nov 2009 13:30:12 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-list-all-constraints-of-database-or-table/</guid>
<description><![CDATA[List all Constraints of Database or Table Many times when we are using DML commands like: INSERT, UP]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>List all Constraints of Database or Table</strong></p>
<p>Many times when we are using <strong>DML</strong> commands like:<span style="color:#0000ff;"> INSERT</span>, <span style="color:#0000ff;">UPDATE</span>, <span style="color:#0000ff;">DELETE</span>, we get <strong>errors</strong> because one or the other constraint is set on the table. It get really annoying when we are new to a Database and don’t know what constraints are set on the tables.</p>
<p>It would be of great help if we get the <strong>list of all the constraints</strong> in the database. Below are two methods to do the same.</p>
<p><strong>Method 1</strong></p>
<p>Use <span style="color:#008000;">sys.objects</span> to get the constraint information.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;"> &#8212; To Display all the Constraint in the Database</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> * F<span style="color:#0000ff;">ROM</span><span style="color:#008000;"> sys.objects</span></p>
<p style="padding-left:60px;"><span style="color:#0000ff;">WHERE </span>type_desc <span style="color:#0000ff;">LIKE</span><span style="color:#ff0000;"> &#8216;%CONSTRAINT&#8217;</span></p>
</div>
<p>The above query will display all the fields of <span style="color:#008000;">sys.objects</span>. We can refine the above query to display the result more tasteful.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; To Display all the Constraints in the Database</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;"> OBJECT_NAME<span style="color:#000000;">(object_id)</span></span> <span style="color:#0000ff;">AS </span>ConstraintName,</p>
<p style="padding-left:90px;"><span style="color:#ff00ff;">SCHEMA_NAME</span>(schema_id) <span style="color:#0000ff;">AS</span> SchemaName,</p>
<p style="padding-left:90px;"><span style="color:#ff00ff;">OBJECT_NAME</span>(parent_object_id)<span style="color:#0000ff;"> AS </span>TableName,</p>
<p style="padding-left:90px;">type_desc<span style="color:#0000ff;"> AS</span> ConstraintType</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">FROM<span style="color:#008000;"> </span></span><span style="color:#008000;">sys.objects</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">WHERE</span> type_desc <span style="color:#0000ff;">LIKE <span style="color:#ff0000;">&#8216;</span></span><span style="color:#ff0000;">%CONSTRAINT&#8217;</span></p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; To Display all the Constraints in table ‘Employee’</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT </span> <span style="color:#ff00ff;"> OBJECT_NAME</span>(object_id) <span style="color:#0000ff;">AS</span> ConstraintName,</p>
<p style="padding-left:90px;"><span style="color:#ff00ff;">SCHEMA_NAME</span>(schema_id) <span style="color:#0000ff;">AS</span> SchemaName,</p>
<p style="padding-left:90px;">type_desc <span style="color:#0000ff;">AS</span> ConstraintType</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">FROM</span> <span style="color:#008000;">sys.objects</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">WHERE </span>type_desc <span style="color:#0000ff;">LIKE</span> <span style="color:#ff0000;">&#8216;%CONSTRAINT&#8217; </span><span style="color:#0000ff;">AND</span> <span style="color:#ff00ff;">OBJECT_NAME</span>(parent_object_id)=<span style="color:#ff0000;">&#8216;Employee&#8217;</span></p>
</div>
<p><strong>Method 2</strong></p>
<p>Use <span style="color:#008000;">INFORMATION_SCHEMA.TABLE_CONSTRAINTS </span>to get the constraint information. This query has one <strong>shortcoming;</strong> it won’t display <span style="color:#0000ff;">DEFAULT</span> constraints of the database</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; To Display all the Constraints in the Database</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> * <span style="color:#0000ff;">FROM</span> <span style="color:#008000;">INFORMATION_SCHEMA.TABLE_CONSTRAINTS</span></p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; To Display all the Constraints in table &#8216;Employee&#8217;</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> * <span style="color:#0000ff;">FROM</span> I<span style="color:#008000;">NFORMATION_SCHEMA.TABLE_CONSTRAINTS</span></p>
<p style="padding-left:60px;"><span style="color:#0000ff;">WHERE</span> TABLE_NAME=<span style="color:#ff0000;">&#8216;Employee&#8217;</span></p>
</div>
<p>To display <span style="color:#0000ff;">DEFAULT</span> constraints in the database we can use following SQL Statement.</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; To Display Default Constraints in Database</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT </span> <span style="color:#ff00ff;">OBJECT_NAME</span>(PARENT_OBJECT_ID)<span style="color:#0000ff;"> AS</span> TABLE_NAME,</p>
<p style="padding-left:90px;"><span style="color:#ff00ff;">COL_NAME </span>(PARENT_OBJECT_ID, PARENT_COLUMN_ID) <span style="color:#0000ff;">AS </span>COLUMN_NAME,</p>
<p style="padding-left:90px;">NAME<span style="color:#0000ff;"> AS </span>DEFAULT_CONSTRAINT_NAME</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">FROM</span><span style="color:#008000;"> SYS.DEFAULT_CONSTRAINTS</span></p>
</div>
<p><strong>See also:</strong></p>
<p><a href="http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-drop-all-table-constraints/" target="_self">SQL Server &#8211; Drop All Table Constraints</a></p>
<p><a href="http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-list-all-foreign-key-constraints-of-database-or-table/" target="_blank">SQL Server &#8211; Stored Procedure to Drop All Database Constraints</a></p>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - Find Nth Highest or Lowest Value in Table]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-find-nth-highest-or-lowest-value-in-table/</link>
<pubDate>Wed, 04 Nov 2009 06:25:25 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-find-nth-highest-or-lowest-value-in-table/</guid>
<description><![CDATA[Find Nth Highest or Lowest Value in Table This one is a tricky question. We all assume that this is ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Find Nth Highest or Lowest Value in Table</strong></p>
<p>This one is a tricky question. We all assume that this is not a big deal, but when this question is asked in the <strong>interviews</strong>, we try all the permutations and combinations of <span style="color:#0000ff;">SELECT</span> statements, but are never close to the answer.</p>
<p>There are many solutions to this problem. I have listed down some of the simple methods to find out Nth highest and Nth Lowest values in the table.</p>
<p><strong>Method 1</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;"> USE</span> AdventureWorks;</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique third highest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT TOP</span> 1 UnitPrice <span style="color:#0000ff;">FROM</span></p>
<p style="padding-left:30px;">(<span style="color:#0000ff;">SELECT DISTINCT TOP</span> 3 UnitPrice <span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">ORDER BY </span>UnitPrice <span style="color:#0000ff;">DESC</span>) <span style="color:#0000ff;">AS</span> A</p>
<p style="padding-left:30px;"><span style="color:#0000ff;"> </span><span style="color:#0000ff;">ORDER BY</span> UnitPrice;</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique second lowest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT TOP </span>1 UnitPrice <span style="color:#0000ff;">FROM<br />
</span></p>
<p style="padding-left:30px;">(<span style="color:#0000ff;">SELECT DISTINCT TOP </span>2 UnitPrice <span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">ORDER BY </span>UnitPrice) <span style="color:#0000ff;">AS</span> A</p>
<p style="padding-left:30px;"><span style="color:#0000ff;"> </span> <span style="color:#0000ff;">ORDER BY </span>UnitPrice<span style="color:#0000ff;"> DESC</span>;</p>
<p style="padding-left:30px;">
</div>
<p><strong>Method 2</strong></p>
<p><strong> </strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique third highest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT TOP </span>1 UnitPrice <span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">WHERE </span>UnitPrice<span style="color:#0000ff;"> IN</span></p>
<p style="padding-left:30px;">(<span style="color:#0000ff;">SELECT DISTINCT TOP </span>3 UnitPrice <span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">ORDER BY</span> UnitPrice <span style="color:#0000ff;">DESC</span>)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">ORDER BY </span>UnitPrice;</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique second lowest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT TOP </span>1 UnitPrice <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">WHERE</span> UnitPrice <span style="color:#0000ff;">IN</span></p>
<p style="padding-left:30px;">(<span style="color:#0000ff;">SELECT DISTINCT TOP </span>2 UnitPrice <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">ORDER BY</span> UnitPrice)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">ORDER BY </span>UnitPrice <span style="color:#0000ff;">DESC</span>;</p>
</div>
<p><strong>Method 3</strong></p>
<p><strong> </strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique third highest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">MIN</span>(UnitPrice) <span style="color:#0000ff;">FROM</span></p>
<p style="padding-left:30px;">(<span style="color:#0000ff;">SELECT DISTINCT TOP</span> 3 UnitPrice <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">ORDER BY</span> UnitPrice DESC) <span style="color:#0000ff;">AS</span> A;</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique second lowest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span><span style="color:#ff00ff;"> MAX</span>(UnitPrice)<span style="color:#0000ff;"> FROM</span></p>
<p style="padding-left:30px;">(<span style="color:#0000ff;">SELECT DISTINCT TOP</span> 2 UnitPrice<span style="color:#0000ff;"> FROM</span> Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">ORDER BY</span> UnitPrice) <span style="color:#0000ff;">AS</span> A;</p>
</div>
<p><strong>Method 4</strong></p>
<p><strong> </strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique third highest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">MIN</span>(UnitPrice) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">WHERE</span> UnitPrice<span style="color:#0000ff;"> IN</span></p>
<p style="padding-left:30px;">(<span style="color:#0000ff;">SELECT DISTINCT TOP</span> 3 UnitPrice <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">ORDER BY</span> UnitPrice <span style="color:#0000ff;">DESC</span>);</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique second lowest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">MAX</span>(UnitPrice)<span style="color:#0000ff;"> FROM </span>Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">WHERE</span> UnitPrice<span style="color:#0000ff;"> IN</span></p>
<p style="padding-left:30px;">(<span style="color:#0000ff;">SELECT DISTINCT TOP</span> 2 UnitPrice <span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail<span style="color:#0000ff;"> ORDER BY</span> UnitPrice);</p>
</div>
<p><strong>Method 5</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique third highest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT </span><span style="color:#ff00ff;">MAX</span>(P1.UnitPrice) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail P1</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">WHERE</span> 3 &#60;= (<span style="color:#0000ff;">SELECT </span><span style="color:#ff00ff;">COUNT</span>(<span style="color:#0000ff;">DISTINCT</span> P2.UnitPrice)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail P2 <span style="color:#0000ff;">WHERE</span> P1.UnitPrice &#60;= P2.UnitPrice);</p>
</div>
<p><strong> </strong></p>
<p><strong>Method 6</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finding unique third highest UnitPrice value from table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT DISTINCT </span>P1.UnitPrice <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail P1</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">WHERE</span> 3 = (<span style="color:#0000ff;">SELECT </span><span style="color:#ff00ff;">COUNT</span>(<span style="color:#0000ff;">DISTINCT</span> P2.UnitPrice)</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail P2<span style="color:#0000ff;"> WHERE</span> P1.UnitPrice&#60;=P2.UnitPrice);</p>
</div>
<p>Hope you find this useful.</p>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[General Notes]]></title>
<link>http://ambatisreedharworks.wordpress.com/2009/11/02/general-notes/</link>
<pubDate>Mon, 02 Nov 2009 16:12:45 +0000</pubDate>
<dc:creator>ambatisreedhar</dc:creator>
<guid>http://ambatisreedharworks.wordpress.com/2009/11/02/general-notes/</guid>
<description><![CDATA[Convert.ToDateTime(date1).ToString(&#8220;dd-MMM-yyyy&#8221;); &#8212;&#8211; declare @myxml xml; se]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Convert.ToDateTime(date1).ToString(&#8220;dd-MMM-yyyy&#8221;);</p>
<p>&#8212;&#8211;</p>
<p>declare @myxml xml;</p>
<p>select @myxml = &#8216;&#60;ParameterValues&#62;</p>
<p>&#60;ParameterValue&#62;<br />
&#60;Name&#62;TO&#60;/Name&#62;<br />
&#60;Value&#62;myemail@mail.com&#60;/Value&#62;<br />
&#60;/ParameterValue&#62;</p>
<p>&#60;ParameterValue&#62;<br />
&#60;Name&#62;BCC&#60;/Name&#62;<br />
&#60;Value&#62;myemail@mail.com&#60;/Value&#62;<br />
&#60;/ParameterValue&#62;</p>
<p>&#60;ParameterValue&#62;<br />
&#60;Name&#62;IncludeReport&#60;/Name&#62;<br />
&#60;Value&#62;True&#60;/Value&#62;<br />
&#60;/ParameterValue&#62;</p>
<p>&#60;ParameterValue&#62;<br />
&#60;Name&#62;Subject&#60;/Name&#62;<br />
&#60;Value&#62;Customers in Switaly&#60;/Value&#62;<br />
&#60;/ParameterValue&#62;</p>
<p>&#60;/ParameterValues&#62;&#8217;</p>
<p>&#8211;select @myxml</p>
<p>&#8211;select @myxml.query(&#8216;/ParameterValues/ParameterValue/Value[../Name = ''Subject'']&#8216;)<br />
select @myxml.query(&#8216;/ParameterValues/ParameterValue/Value12&#8242;)</p>
<p>=======================</p>
<p>select * from wsiagingreport<br />
select [XmlQuerySql].value(&#8216;(/ROOT/Slot1/SlotPeriodValue)[1]&#8216;, &#8216;varchar(200)&#8217;) as Slot1PeriodValue,<br />
[XmlQuerySql].value(&#8216;(/ROOT/Slot1/SlotPeriodType)[1]&#8216;, &#8216;varchar(200)&#8217;) as SlotPeriodType,<br />
[XmlQuerySql].value(&#8216;(/ROOT/Slot1/ThresholdType)[1]&#8216;, &#8216;varchar(200)&#8217;) as ThresholdType,<br />
[XmlQuerySql].value(&#8216;(/ROOT/Slot1/ThresholdValue)[1]&#8216;, &#8216;varchar(200)&#8217;) as ThresholdValue<br />
from wsiagingreport</p>
<p>====================================</p>
<p>Except in sqlserver is equivalent to Minus in ORACLE</p>
<p>===</p>
<p>usage of case when then else end<br />
&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<br />
select @Slot1_Count = count(*) from wsiincident<br />
where @Slot1_PeriodValue &#62;=<br />
case when @Slot1_PeriodType =&#8217;Hour&#8217;<br />
     then datediff(hour, sourcetoolcreateddate,getdate())  <br />
     when @Slot1_PeriodType =&#8217;Day&#8217;<br />
     then datediff(Day, sourcetoolcreateddate,getdate())<br />
     when @Slot1_PeriodType =&#8217;Week&#8217;<br />
     then datediff(Week, sourcetoolcreateddate,getdate())<br />
     when @Slot1_PeriodType =&#8217;Fortnight&#8217;<br />
     then datediff(Day, sourcetoolcreateddate,getdate())/14<br />
     when @Slot1_PeriodType =&#8217;Month&#8217;<br />
     then datediff(Month, sourcetoolcreateddate,getdate())<br />
     when @Slot1_PeriodType =&#8217;Quarter&#8217;<br />
     then datediff(Quarter, sourcetoolcreateddate,getdate())<br />
     when  @Slot1_PeriodType =&#8217;Year&#8217;<br />
     then datediff(Year, sourcetoolcreateddate,getdate())<br />
     else 0 end</p>
<p>===================================</p>
<p>select datediff(Year,&#8217;2003-12-12&#8242;,getdate())<br />
declare @ss nvarchar(100)<br />
set @ss = &#8216;h&#8217;<br />
select case when @ss =&#8217;h&#8217; then datediff(hour,&#8217;2003-12-12&#8242;,getdate())<br />
   when @ss =&#8217;m&#8217; then datediff(minute,&#8217;2003-12-12&#8242;,getdate())<br />
   when @ss =&#8217;s&#8217; then datediff(second,&#8217;2003-12-12&#8242;,getdate())<br />
   else 0 end</p>
<p>============================================<br />
suppose in a sp u need like this</p>
<p>create proc p_c<br />
as<br />
begin<br />
select * from table<br />
where names in (&#8217;s,g,d&#8217;)<br />
end  .. this will work</p>
<p>but<br />
create proc p_c<br />
@strings nvarchar(1000)<br />
as<br />
begin<br />
select * from table<br />
where names in (@strings )<br />
end  .. this wont work as strings is a parameter.</p>
<p>To solve this problem<br />
create a splitstring function and split the string and insert into a temporary table</p>
<p>create proc p_c<br />
@strings nvarchar(1000)<br />
as<br />
begin<br />
select * from table<br />
where names in (select names from db0.splitstrings(@strings))<br />
end  .. this will work<br />
splitstring function is:<br />
ALTER FUNCTION [dbo].[SplitStrings](@String varchar(8000), @Delimiter char(1))       </p>
<p>      returns @temptable TABLE (items varchar(8000))       </p>
<p>as       </p>
<p>begin       </p>
<p>    declare @idx int       </p>
<p>    declare @slice varchar(8000)       </p>
<p>&#160;</p>
<p>    select @idx = 1       </p>
<p>        if len(@String)&#60;1 or @String is null  return       </p>
<p>&#160;</p>
<p>    while @idx!= 0       </p>
<p>    begin       </p>
<p>        set @idx = charindex(@Delimiter,@String)       </p>
<p>        if @idx!=0       </p>
<p>            set @slice = left(@String,@idx &#8211; 1)       </p>
<p>        else       </p>
<p>            set @slice = @String       </p>
<p>&#160;</p>
<p>        if(len(@slice)&#62;0)  </p>
<p>            insert into @temptable(Items) values(@slice)       </p>
<p>&#160;</p>
<p>        set @String = right(@String,len(@String) &#8211; @idx)       </p>
<p>        if len(@String) = 0 break       </p>
<p>    end   </p>
<p>return       </p>
<p>end </p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
<p>usage : where id in (select id from [SplitStrings](&#8216;a,b&#8217;,',&#8217;))<br />
===================================</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - How to Handle Single Quote in String]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/11/02/sql-server-how-to-handle-single-quote-in-string/</link>
<pubDate>Mon, 02 Nov 2009 13:02:27 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/11/02/sql-server-how-to-handle-single-quote-in-string/</guid>
<description><![CDATA[How to Handle Single Quote in String This is the common one-time problem (not for all ) faced by a n]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>How to Handle Single Quote in String</strong></p>
<p>This is the common one-time problem (not for all <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) faced by a new DBA Developer, and even I did.</p>
<p>The solution to this problem is rather simple. Use an <strong>extra single quote</strong>, with the quote character occurring in the string.</p>
<p>See the example below:</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="text-align:left;padding-left:30px;"><span style="color:#008000;">&#8211; The Insert Satement below will give and error</span></p>
<p style="text-align:left;padding-left:30px;"><span style="color:#0000ff;">INSERT INTO</span> Employee<span style="color:#0000ff;"> VALUES</span> (1003, &#8216;Patrick&#8217;, &#8216;O&#8217;Brain&#8217;)</p>
</div>
<p>Error Message</p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px 4px 4px 34px;"><span style="color:#ff0000;">Msg 105, Unclosed quotation mark after the character string </span></div>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Correct Statement</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">INSERT INTO</span> Employee <span style="color:#0000ff;">VALUES</span> (1003, &#8216;Patrick&#8217;, &#8216;O&#8221;Brain&#8217;)</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Similarly you can use it in WHERE clause also</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> * <span style="color:#0000ff;">FROM</span> Employee <span style="color:#0000ff;">WHERE </span>LastName=&#8217;O&#8221;Brain&#8217;</p>
</div>
<p><strong>See also:</strong></p>
<p><a title="Function to split comma delimited String or List" href="http://bhaveshgpatel.wordpress.com/2009/09/25/sql-server-function-to-split-comma-delimited-string-or-list/" target="_blank">Function to split comma delimited String or List</a></p>
<p><a title="How to handle single quote in sqlquery string?" href="http://bhaveshgpatel.wordpress.com/2009/10/08/sql-server-how-to-handle-single-quote-in-sqlquery-string/" target="_blank">How to handle single quote in sqlquery string?</a></p>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQLAuthority News - New PASS President Rushabh Mehta]]></title>
<link>http://blog.sqlauthority.com/2009/10/31/sqlauthority-news-new-pass-president-rushabh-mehta/</link>
<pubDate>Sat, 31 Oct 2009 01:30:40 +0000</pubDate>
<dc:creator>pinaldave</dc:creator>
<guid>http://blog.sqlauthority.com/2009/10/31/sqlauthority-news-new-pass-president-rushabh-mehta/</guid>
<description><![CDATA[The Professional Association for SQL Server (PASS) is an independent, not-for-profit association, de]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;">The Professional Association for SQL Server (PASS) is an independent, not-for-profit association, dedicated to supporting, educating, and promoting the Microsoft SQL Server community. From local user groups and special interest groups (Virtual Chapters) to webcasts and the annual PASS Community Summit – the largest gathering of SQL Server professionals in the world – PASS is dedicated to helping its members Connect, Share, and Learn.</p>
<p style="text-align:justify;">Today was a big day as PASS announced the executive board members for the term starting on Jan 1, 2010. I would like to express my congratulations to all new executives of PASS. Please read official <a href="http://www.sqlpass.org/Community/PASSBlog/articleType/ArticleView/articleId/118.aspx" target="_blank">press note here</a>.</p>
<p style="text-align:justify;">The newly elected board members at executive positions are as following:</p>
<ul style="text-align:justify;">
<li><strong>Rushabh Mehta</strong> &#8211; President</li>
<li><strong>Bill Graziano</strong> &#8211; Executive Vice President, Finance</li>
<li><strong>Rick Heiges</strong> &#8211; Vice President, Marketing</li>
</ul>
<p style="text-align:justify;">A little bit more details about executives.</p>
<p style="text-align:justify;"><strong><img class="alignleft" style="margin:5px;" src="http://www.pinaldave.com/bimg/rushabhmehta.jpg" alt="" width="128" height="191" />Rushabh Mehta</strong> is a Mentor for Solid Quality Mentors&#8217; global Business Intelligence Division and the Managing Director for Solid Quality India. Rushabh has worked with Microsoft SQL Server since 1998 and has designed and developed BI systems on the Microsoft platform since 2001, including a predictive analysis system, a health-care analysis solution, and a multi-terabyte financial decision support system. He has been the lead architect for many large-scale and complex BI solutions for clients such as Publix, Raymond James Financial, Jackson Hewitt, and Checkers. Rushabh has been an active volunteer with PASS since 2000 and has also served on the board  for a number of years. Rushabh is also a SQL Server MVP and a frequent speaker at large conferences and PASS Chapters around the world.</p>
<p style="text-align:justify;"><strong><img class="alignleft" style="margin:5px;" src="http://www.pinaldave.com/bimg/BillGraziano2.jpg" alt="" width="120" height="157" /></strong></p>
<p style="text-align:justify;"><strong>Bill Graziano</strong> is an active member of PASS since 2001, Bill currently serves on the Board of Directors, where he is responsible for the overall marketing for PASS and PASS Summit. Bill co-founded SQLTeam.com, a web site for SQL Server developers and database administrators. In addition to managing the site, he writes articles and helps users with their most vexing problems. An involved participant in the SQL Server community for seven years, Bill was recognized as a SQL Server MVP in 2004 and still holds that designation.</p>
<p style="text-align:justify;"><strong><img class="alignleft" style="margin:5px;" src="http://www.pinaldave.com/bimg/RickHeiges.jpg" alt="" width="120" height="153" /></strong></p>
<p style="text-align:justify;"><strong>Rick Heiges</strong> is a Sr. Solutions Consultant with Scalability Experts working with customers on solutions within the SQL Server environment and educating users on SQL Server 2005 by speaking at user groups, conferences, labs, and road shows across the USA, Europe, and Africa. He holds an MBA and a M.S. in MIS as well as a B.S. in Computer Science. In addition, he also has attained MCTS:SQL2005 and MCITP:DBA certifications.</p>
<p style="text-align:justify;">
<p style="text-align:justify;">Not only are these three executives experts in their domain, but have been friends for many years. Here are few of their photos from their activities at old PASS events.</p>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img class="  " title="Rushabh and Bill - Archive Photo" src="http://www.pinaldave.com/bimg/rm1.jpg" alt="" width="410" height="307" /></dt>
<dd class="wp-caption-dd">Rushabh and Bill</dd>
</dl>
</div>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img class="  " title="Rushabh and Rick - Archive Photo" src="http://www.pinaldave.com/bimg/rm.jpg" alt="" width="410" height="307" /></dt>
<dd class="wp-caption-dd">Rushabh and Rick</dd>
</dl>
</div>
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img class="  " title="Kevin Kline, Rick and Rushabh - Archive Photo" src="http://www.pinaldave.com/bimg/rm2a.jpg" alt="" width="410" height="312" /></dt>
<dd class="wp-caption-dd">Kevin Kline, Rick and Rushabh</dd>
</dl>
</div>
<p style="text-align:justify;">Many congratulations to all of you. SQL Server community has lots of expectation from you and we are confident that you will not only satisfy them but will go way beyond our imaginations.</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;"><strong>Image courtesy:</strong> Rick Heiges, Rushabh Mehta, SQL PASS</p>
<p style="text-align:justify;">
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server - Set Functions - COUNT, MAX, MIN, SUM and AVG]]></title>
<link>http://bhaveshgpatel.wordpress.com/2009/10/29/sql-server-set-functions-count-max-min-sum-and-avg/</link>
<pubDate>Thu, 29 Oct 2009 14:51:16 +0000</pubDate>
<dc:creator>Bhavesh Patel</dc:creator>
<guid>http://bhaveshgpatel.wordpress.com/2009/10/29/sql-server-set-functions-count-max-min-sum-and-avg/</guid>
<description><![CDATA[Set Functions &#8211; COUNT, MAX, MIN, SUM and AVG Many times the information we require from table ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Set Functions &#8211; COUNT, MAX, MIN, SUM and AVG</strong></p>
<p>Many times the information we require from table doesn’t relate to individual rows but to set of rows. In such case we can use <strong>Set functions</strong> provided by the SQL Server. These function are <span style="color:#ff00ff;">COUNT</span>, <span style="color:#ff00ff;">MAX</span>, <span style="color:#ff00ff;">MIN</span>, <span style="color:#ff00ff;">SUM</span> and <span style="color:#ff00ff;">AVG</span>. <strong>Set functions</strong> operate on groups of rows.</p>
<p><span style="color:#800000;"> <strong>1. COUNT</strong></span></p>
<p>The <span style="color:#ff00ff;">COUNT</span> function returns the rows count in the table.  When used with <span style="color:#0000ff;">WHERE</span> clause, only number of rows which satisfy the condition will be returned. The <span style="color:#0000ff;">DISTINCT</span> can be used to get the count of rows with unique values.</p>
<p><strong>Example</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#0000ff;">USE</span> AdventureWorks</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Calculates the row count of the table</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">COUNT</span>(*) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Calculates the row count which satisfy the condition</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">COUNT</span>(*) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">WHERE</span> PurchaseOrderID=18</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Calculates the number of non-null values for that column</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span><span style="color:#ff00ff;"> COUNT</span>(ProductID) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Calculates the number of distinct non-null values for that column</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT </span><span style="color:#ff00ff;">COUNT</span>(<span style="color:#0000ff;">DISTINCT</span>(ProductID)) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail</p>
</div>
<p><span style="color:#800000;"><strong>2. MAX</strong></span></p>
<p>The<span style="color:#ff00ff;"> MAX </span>function returns the maximum value in the specified column. The <span style="color:#ff00ff;">MAX </span>function can also be used as the part of sub-query.</p>
<p><strong>Example</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finds the maximum value for the column</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span><span style="color:#ff00ff;"> MAX</span>(OrderQty) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; It can be used as part of subquery</span></p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Displays all the records having maximum OrderQty</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> * <span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">WHERE</span> OrderQty =</p>
<p style="padding-left:60px;">(<span style="color:#0000ff;">SELECT </span><span style="color:#ff00ff;">MAX</span>(OrderQty) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail)</p>
</div>
<p><span style="color:#800000;"><strong>3. MIN</strong></span></p>
<p>The <span style="color:#ff00ff;">MIN</span> function returns the minimum value in the specified column. The <span style="color:#ff00ff;">MIN </span>function can also be used as the part of sub-query.</p>
<p><strong>Example</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finds the minimum value for the column</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">MIN</span>(OrderQty) <span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; It can be used as part of subquery</span></p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Displays all the records having minimum OrderQty</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> * <span style="color:#0000ff;">FROM </span>Purchasing.PurchaseOrderDetail <span style="color:#0000ff;">WHERE</span> OrderQty =</p>
<p style="padding-left:60px;">(<span style="color:#0000ff;">SELECT</span><span style="color:#ff00ff;"> MIN</span>(OrderQty) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail)</p>
</div>
<p><span style="color:#800000;"><strong>4. SUM</strong></span></p>
<p>The <span style="color:#ff00ff;">SUM</span> function adds up the values in a specified column. The column must be of one of <strong>numeric</strong> data types. The <span style="color:#0000ff;">DISTINCT</span> can be used to get the sum of only unique values.</p>
<p><strong>Example</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finds the total sum for the column</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">SUM</span>(OrderQty) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finds the sum of distinct values for the column</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">SUM</span>(<span style="color:#0000ff;">DISTINCT</span>(OrderQty)) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail</p>
</div>
<p><span style="color:#800000;"><strong>5. AVG</strong></span></p>
<p>The<span style="color:#ff00ff;"> AVG </span>function returns the average of all the values in the specified column. As with <span style="color:#ff00ff;">SUM </span>function, the column must be of one of <strong>numeric</strong> data types. The <span style="color:#0000ff;">DISTINCT</span> can be used to get the average of only unique values.</p>
<p><strong>Example</strong></p>
<div style="border:1px solid gray;overflow:auto;font-size:9pt;font-family:Arial,Courier New,Helvetica,sans-serif;width:97.5%;cursor:text;background-color:#fffccf;max-height:400px;margin:20px 0 30px;padding:4px;">
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finds the average for the column</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">AVG</span>(OrderQty)<span style="color:#0000ff;"> FROM</span> Purchasing.PurchaseOrderDetail</p>
<p style="padding-left:30px;"><span style="color:#008000;">&#8211; Finds the average of distinct values for the column</span></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">SELECT</span> <span style="color:#ff00ff;">AVG</span>(<span style="color:#0000ff;">DISTINCT</span>(OrderQty)) <span style="color:#0000ff;">FROM</span> Purchasing.PurchaseOrderDetail</p>
</div>
<p>Good Luck!</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
