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

<channel>
	<title>Bhavesh Patel&#039;s Blog</title>
	<atom:link href="http://bhaveshgpatel.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bhaveshgpatel.wordpress.com</link>
	<description>&#039;New Dreams&#039; to make &#039;New World&#039;</description>
	<lastBuildDate>Thu, 22 Dec 2011 15:21:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bhaveshgpatel.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Bhavesh Patel&#039;s Blog</title>
		<link>http://bhaveshgpatel.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bhaveshgpatel.wordpress.com/osd.xml" title="Bhavesh Patel&#039;s Blog" />
	<atom:link rel='hub' href='http://bhaveshgpatel.wordpress.com/?pushpress=hub'/>
		<item>
		<title>SQL Server Code Name</title>
		<link>http://bhaveshgpatel.wordpress.com/2009/11/24/sql-server-code-name/</link>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/24/sql-server-code-name/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 06:32:46 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Basics]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2000 code name]]></category>
		<category><![CDATA[SQL Server 2005 code name]]></category>
		<category><![CDATA[SQL Server 2008 code name]]></category>
		<category><![CDATA[SQL Server code name]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=298</guid>
		<description><![CDATA[SQL Server Code Name Yesterday, I came across a very interesting question on one of the SQL Servers Online Forums. Question – What is the code name of SQL Server 2005? Well I knew that the Microsoft gives code names to it products when they are in developmental stages. But I never came across the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=298&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>&nbsp;</p>
<p>Good Luck!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/298/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=298&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/24/sql-server-code-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server &#8211; DBCC Commands</title>
		<link>http://bhaveshgpatel.wordpress.com/2009/11/19/sql-server-dbcc-commands/</link>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/19/sql-server-dbcc-commands/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 12:53:41 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[DBCC]]></category>
		<category><![CDATA[SQL DBCC]]></category>
		<category><![CDATA[DBCC CLEANTABLE]]></category>
		<category><![CDATA[DBCC DBREINDEX]]></category>
		<category><![CDATA[DBCC DROPCLEANBUFFERS]]></category>
		<category><![CDATA[DBCC FREEPROCCACHE]]></category>
		<category><![CDATA[DBCC INDEXDEFRAG]]></category>
		<category><![CDATA[DBCC SHRINKDATABASE]]></category>
		<category><![CDATA[DBCC SHRINKFILE]]></category>
		<category><![CDATA[DBCC UPDATEUSAGE]]></category>
		<category><![CDATA[DBCC CONCURRENCYVIOLATION]]></category>
		<category><![CDATA[DBCC INPUTBUFFER]]></category>
		<category><![CDATA[DBCC OPENTRAN]]></category>
		<category><![CDATA[DBCC OUTPUTBUFFER]]></category>
		<category><![CDATA[DBCC PROCCACHE]]></category>
		<category><![CDATA[DBCC SHOW_STATISTICS]]></category>
		<category><![CDATA[DBCC SHOWCONTIG]]></category>
		<category><![CDATA[DBCC SQLPERF]]></category>
		<category><![CDATA[DBCC TRACESTATUS]]></category>
		<category><![CDATA[DBCC USEROPTIONS]]></category>
		<category><![CDATA[DBCC CHECKALLOC]]></category>
		<category><![CDATA[DBCC CHECKCATALOG]]></category>
		<category><![CDATA[DBCC CHECKCONSTRAINTS]]></category>
		<category><![CDATA[DBCC CHECKDB]]></category>
		<category><![CDATA[DBCC CHECKFILEGROUP]]></category>
		<category><![CDATA[DBCC CHECKIDENT]]></category>
		<category><![CDATA[DBCC CHECKTABLE]]></category>
		<category><![CDATA[DBCC dllname]]></category>
		<category><![CDATA[DBCC TRACEOFF]]></category>
		<category><![CDATA[DBCC HELP]]></category>
		<category><![CDATA[DBCC TRACEON]]></category>
		<category><![CDATA[DBCC Miscellaneous Commands]]></category>
		<category><![CDATA[DBCC Validation Commands]]></category>
		<category><![CDATA[DBCC Informational Commands]]></category>
		<category><![CDATA[DBCC Maintenance Commands]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=295</guid>
		<description><![CDATA[DBCC (Database consistency checker) are used to check the consistency of the databases. The DBCC commands are most useful for performance and trouble shooting exercises. I have listed down and explained all the DBCC commands available in SQL Server 2005, with examples. The DBCC Commands broadly falls into four categories: Maintenance Informational Validation Miscellaneous Maintenance [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=295&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=295&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/19/sql-server-dbcc-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server &#8211; System Stored Procedure Script</title>
		<link>http://bhaveshgpatel.wordpress.com/2009/11/09/sql-server-system-stored-procedure-script/</link>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/09/sql-server-system-stored-procedure-script/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 05:30:24 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[sp_helptext]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[System Stored Procedure code]]></category>
		<category><![CDATA[System Stored Procedure Script]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=290</guid>
		<description><![CDATA[System Stored Procedure Script Have you seen script of System Stored Procedure of SQL Server? Well if you are curious creature like me, then why not see it. To do that, we need to use another System Stored Procedure sp_helptext. It will display the script behind the specified System Stored Procedure. Syntax: EXEC sp_helptext &#8216;System [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=290&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Good Luck!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/290/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=290&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/09/sql-server-system-stored-procedure-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Bhavesh Patel is now 1000 times Stronger</title>
		<link>http://bhaveshgpatel.wordpress.com/2009/11/09/bhavesh-patel-is-now-1000-times-stronger/</link>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/09/bhavesh-patel-is-now-1000-times-stronger/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 05:23:25 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[Life is Beautiful]]></category>
		<category><![CDATA[1000 readers]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[DBA Bhavesh Patel]]></category>
		<category><![CDATA[SQL Bhavesh Patel]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=287</guid>
		<description><![CDATA[Bhavesh Patel is now 1000 times Stronger I don’t know what are you are thinking after reading the title of this post? Did you see the readers count on the right side? Yes, it shows 1000+ readers for this blog. I started this blog as an experiment few months back when I had just started [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=287&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Bhavesh Patel is now 1000 times Stronger</strong></p>
<p>I don’t know what are you are thinking after reading the title of this post? Did you see the readers count on the right side? Yes, it shows <strong>1000+ readers</strong> for this blog.</p>
<p>I started this blog as an experiment few months back when I had just started my career as DBA professional. I wanted to share the knowledge I acquire in this profession with the <strong>new DBA’s</strong> or “<strong>want to be DBA’s</strong>”.</p>
<p>It has been a great journey from 0 to 1 then 10 and 100 and now <strong>1000+. </strong>I hope posts on this blog are of any use to the readers. I dreamed of positive response from Netizens, but never expected to be this good in such a short period of time.</p>
<p>Till now, most of the posts were related to TSQL commands and some basic programming. Now I shall move on next level of DBA, that is <strong>SQL Server Management</strong>.  And shall post more advance topics related to DBA in the future.</p>
<p><strong>I’ve always believed in sharing, since I think it makes us all stronger.</strong></p>
<p>Thanks,</p>
<p>Bhavesh Patel</p>
<p><strong>Junior DBA</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/287/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=287&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/09/bhavesh-patel-is-now-1000-times-stronger/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server &#8211; SERVERPROPERTY Function</title>
		<link>http://bhaveshgpatel.wordpress.com/2009/11/07/sql-server-serverproperty-function/</link>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/07/sql-server-serverproperty-function/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 05:48:33 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[list server property]]></category>
		<category><![CDATA[SERVERPROPERTY]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[system function]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=261</guid>
		<description><![CDATA[SERVERPROPERTY Function How does one get list all Server Properties? Well, we can use a very helpful system function SERVERPROPERTY. It will return information about the server instance for a specified property. Syntax: SERVERPROPERTY (propertyname) I have kept the following script in my archives, you may do the same. &#8211; Returns all the property information [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=261&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>&nbsp;</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>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=261&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/07/sql-server-serverproperty-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server &#8211; 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>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-list-all-foreign-key-constraints-of-database-or-table/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 09:15:39 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[List all Foreign Key Constraints of Database]]></category>
		<category><![CDATA[List all Foreign Key Constraints of Table]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=256</guid>
		<description><![CDATA[List all Foreign Key Constraints of Database or Table How often we face this problem? The Foreign Key constraint of the table preventing us from deleting or modifying records. 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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=256&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/256/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=256&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-list-all-foreign-key-constraints-of-database-or-table/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server &#8211; Drop All Table Constraints</title>
		<link>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-drop-all-table-constraints/</link>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-drop-all-table-constraints/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 09:07:37 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[drop table Constraints]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=254</guid>
		<description><![CDATA[Drop All Table Constraints You want to redefine all the constraints set on a Table. To do that you need to first drop all the existing constraints set on the table. Following is the simple script to do so the same: &#8211; To drop all Constraints on a table Employee DECLARE @database NVARCHAR(50) DECLARE @table [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=254&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/254/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=254&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/05/sql-server-drop-all-table-constraints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server &#8211; 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>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-list-all-constraints-of-database-or-table/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 13:30:12 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[List all Constraints of Database]]></category>
		<category><![CDATA[List all Constraints of Table]]></category>
		<category><![CDATA[List Check Constraint]]></category>
		<category><![CDATA[List Default Constraint]]></category>
		<category><![CDATA[List Foreign Key Constraint]]></category>
		<category><![CDATA[List Primary Key Constraint]]></category>
		<category><![CDATA[List Unique Constraint]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=248</guid>
		<description><![CDATA[List all Constraints of Database or Table Many times when we are using DML commands like: INSERT, UPDATE, DELETE, we get errors 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. It [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=248&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/248/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=248&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-list-all-constraints-of-database-or-table/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server &#8211; 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>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-find-nth-highest-or-lowest-value-in-table/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 06:25:25 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[Finding Nth highest value]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[Lowest value]]></category>
		<category><![CDATA[second highest]]></category>
		<category><![CDATA[second lowest]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[third highest]]></category>
		<category><![CDATA[third lowest]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=242</guid>
		<description><![CDATA[Find Nth Highest or Lowest Value in Table This one is a tricky question. We all assume that this is not a big deal, but when this question is asked in the interviews, we try all the permutations and combinations of SELECT statements, but are never close to the answer. There are many solutions to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=242&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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 &lt;= (<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 &lt;= 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&lt;=P2.UnitPrice);</p>
</div>
<p>Hope you find this useful.</p>
<p>Good Luck!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/242/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=242&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-find-nth-highest-or-lowest-value-in-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server &#8211; 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>
		<comments>http://bhaveshgpatel.wordpress.com/2009/11/02/sql-server-how-to-handle-single-quote-in-string/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 13:02:27 +0000</pubDate>
		<dc:creator>Bhavesh Patel</dc:creator>
				<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[Bhavesh Patel]]></category>
		<category><![CDATA[Handle Single Quote in String]]></category>
		<category><![CDATA[Msg 105 Unclosed quotation mark after the character string]]></category>
		<category><![CDATA[nvarchar]]></category>
		<category><![CDATA[quote]]></category>
		<category><![CDATA[quote in varchar]]></category>
		<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Single Quote]]></category>
		<category><![CDATA[single quote character]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://bhaveshgpatel.wordpress.com/?p=236</guid>
		<description><![CDATA[How to Handle Single Quote in String This is the common one-time problem (not for all ) faced by a new DBA Developer, and even I did. The solution to this problem is rather simple. Use an extra single quote, with the quote character occurring in the string. See the example below: &#8211; The Insert [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=236&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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://s1.wp.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>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bhaveshgpatel.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bhaveshgpatel.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bhaveshgpatel.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bhaveshgpatel.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bhaveshgpatel.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bhaveshgpatel.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bhaveshgpatel.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bhaveshgpatel.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bhaveshgpatel.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bhaveshgpatel.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bhaveshgpatel.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bhaveshgpatel.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bhaveshgpatel.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bhaveshgpatel.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bhaveshgpatel.wordpress.com&amp;blog=9108081&amp;post=236&amp;subd=bhaveshgpatel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bhaveshgpatel.wordpress.com/2009/11/02/sql-server-how-to-handle-single-quote-in-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2b7073986e74793ef48b1d96e2a66db7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bhavesh</media:title>
		</media:content>
	</item>
	</channel>
</rss>
