<?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/"
	>

<channel>
	<title>asrar.ca &#187; Performance</title>
	<atom:link href="http://asrar.ca/category/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://asrar.ca</link>
	<description>web design news and tips, hockey ramblings, and music opinions</description>
	<lastBuildDate>Mon, 05 Oct 2009 21:27:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>SQL performance: Count(*) vs. Count(1)</title>
		<link>http://asrar.ca/2009/03/sql-performance-count-vs-count1/</link>
		<comments>http://asrar.ca/2009/03/sql-performance-count-vs-count1/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 01:29:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://asrar.ca/?p=3</guid>
		<description><![CDATA[Counting the number of records in a table or query is a pretty common task for developers. To count the amount of rows returned in a recordset, the syntax is: SELECT Count(*) FROM tablename The code is simple enough, but some people look at the * (asterik) and feel uncomfortable. A developer is always looking [...]]]></description>
			<content:encoded><![CDATA[<p>Counting the number of records in a table or query is a pretty common task for developers. To count the amount of rows returned in a recordset, the syntax is:</p>
<p>SELECT Count(*) FROM tablename</p>
<p>The code is simple enough, but some people look at the * (asterik) and feel uncomfortable. A developer is always looking for ways to improve performance; it&#8217;s understandable to think you can get a performance boost with the following code:</p>
<p>SELECT Count(1) FROM tablename</p>
<p>After all, the asterik is usually used to select all columns in a table, and one should never select columns which are not going to be used. So why select Count(*)?</p>
<p>There are 2 reasons you should always use Count(*) rather than Count(1):</p>
<p><strong>1. Performance</strong></p>
<p>SQL Server Query Optimizer interprets the Count(*) differently from SELECT *. So when it sees Count(*) it automatically follows the quickest execution plan. Using Count(1) may cause the query optimizer fail and thus slow down your application.</p>
<p><strong>2. Results</strong></p>
<p>Count(*) will count all the records in the recordset, while Count(1) will count all non-NULL records in the recordset. So in some rare cases, Count(1) may give you unexpected results.</p>
<p><strong>Conclusion</strong></p>
<p>Always use Count(*) when counting a recordset!</p>
]]></content:encoded>
			<wfw:commentRss>http://asrar.ca/2009/03/sql-performance-count-vs-count1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
