<?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>BI Monkey &#187; Row Count</title>
	<atom:link href="http://www.bimonkey.com/tag/row-count/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bimonkey.com</link>
	<description>James Beresford on Microsoft BI and Consulting in Sydney, Australia</description>
	<lastBuildDate>Mon, 23 Jan 2012 22:01:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>The Row Count Transformation</title>
		<link>http://www.bimonkey.com/2009/08/the-row-count-transformation/</link>
		<comments>http://www.bimonkey.com/2009/08/the-row-count-transformation/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 00:40:30 +0000</pubDate>
		<dc:creator>BI Monkey</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[Row Count]]></category>

		<guid isPermaLink="false">http://www.bimonkey.com/?p=535</guid>
		<description><![CDATA[In this post I will be covering the Row Count Transformation. The sample package can be found here for 2005 and guidelines on use are here. What does the Row Count Transformation do? The Row Count Transformation counts the number of rows that have passed through a Data Flow and puts that count into a [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignnone" style="width: 203px"><img title="The Row Count Transformation" src="http://www.bimonkey.com/uploads/componentreview/rowcount1.jpg" alt="b" width="193" height="72" /><p class="wp-caption-text">Fig 1: The Row Count Transformation</p></div>
<p>In this post I will be covering the Row Count Transformation. The sample package can be found <a title="SQL 2005 SSIS Row Count Transformation Sample (Right Click, Save As)" href="http://www.bimonkey.com/uploads/componentreview/Row%20Count%20Transformation%20Basics%202005.dtsx">here for 2005</a> and guidelines on use are <a title="Using samples from BI Monkey" href="http://www.bimonkey.com/support/using-ssis-samples-from-this-site/">here</a>.</p>
<h2>What does the Row Count Transformation do?</h2>
<p>The Row Count Transformation counts the number of rows that have passed through a Data Flow and puts that count into a variable. Configuration is simple &#8211; all you need to do to is specify the variable name that will hold the row count on the first page of the editor (down at the bottom under &#8220;Custom Properties&#8221;). There&#8217;s a little gotcha here &#8211; whilst the tab for &#8216;<strong>Input Columns</strong>&#8221; is active, if you try to select any columns it will return an error and not allow you to continue.</p>
<p>It is worth noting that the variable is only updated once <span style="text-decoration: underline;">all</span> rows of data have passed through the data flow &#8211; i&#8217;ve demonstrated this in the sample package by adding the variable to a column in a Derived Column &#8211; it returns zero all the way through, so you cannot use the Row Count as a row number generator.</p>
<h2>Where would you use the Row Count Transformation?</h2>
<p>The most obvious use is in logging processes &#8211; for example counting input rows versus outputs rows or counting failed rows. Anywhere you need to track the number of rows being passed through a given data flow.</p>
<p>MSDN Documentation for the Row Count Transformation can be found here for <a title="SQL 2008 Row Count Transformation Documentation on MSDN" href="http://msdn.microsoft.com/en-us/library/ms141136.aspx">2008</a> and here for <a title="SQL 2005 Row Count Transformation Documentation on MSDN" href="http://msdn.microsoft.com/en-us/library/ms141136(SQL.90).aspx">2005</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bimonkey.com/2009/08/the-row-count-transformation/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Count the number of rows in every Table in a Database in no time!</title>
		<link>http://www.bimonkey.com/2009/06/count-the-number-of-rows-in-every-table-in-a-database-in-no-time/</link>
		<comments>http://www.bimonkey.com/2009/06/count-the-number-of-rows-in-every-table-in-a-database-in-no-time/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 04:47:43 +0000</pubDate>
		<dc:creator>BI Monkey</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[DMV]]></category>
		<category><![CDATA[Row Count]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.bimonkey.com/?p=307</guid>
		<description><![CDATA[Here is a piece of T-SQL code that uses DMV&#8217;s (Dynamic Management Views) to give an approximate row count of every table in your database in virtually no time at all. Bear in mind it is running off collected statistics so won&#8217;t always be 100% accurate &#8211; but it&#8217;s far quicker than doing a Count(*) [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a piece of T-SQL code that uses DMV&#8217;s (Dynamic Management Views) to give an <em>approximate </em>row count of every table in your database in virtually no time at all. Bear in mind it is running off collected statistics so won&#8217;t always be 100% accurate &#8211; but it&#8217;s far quicker than doing a Count(*) on a table by table basis when you just need a rough idea when doing sizing. In case you don&#8217;t know what DMV&#8217;s there are, go poke around in SSMS &#8211; [Database] &gt; Views &gt; System Views and see what&#8217;s there. Anyway, the code:</p>
<pre><span style="color: #0000ff;">SELECT</span>    s.[Name] as [Schema]
,        t.[name] as [Table]
,        <span style="color: #ff00ff;">SUM</span>(p.rows) as [RowCount]

<span style="color: #0000ff;">FROM</span> <span style="color: #339966;">sys.schemas</span> s
<span style="color: #808080;">LEFT JOIN</span> <span style="color: #339966;">sys.tables</span> t
<span style="color: #0000ff;">ON</span> s.<span style="color: #ff00ff;">schema_id</span> = t.<span style="color: #ff00ff;">schema_id</span>

<span style="color: #808080;">LEFT JOIN</span> <span style="color: #339966;">sys.partitions</span> p
<span style="color: #0000ff;">ON</span> t.<span style="color: #ff00ff;">object_id</span> = p.<span style="color: #ff00ff;">object_id</span>

<span style="color: #808080;">LEFT JOIN</span>  <span style="color: #339966;">sys.allocation_units</span> a
<span style="color: #0000ff;">ON</span>  p.partition_id = a.container_id

<span style="color: #0000ff;">WHERE</span>    p.index_id  in(0,1) <span style="color: #339966;">-- 0 heap table , 1 table with clustered index</span>
<span style="color: #808080;">AND</span>        p.rows is not null
<span style="color: #808080;">AND</span>        a.type = 1  <span style="color: #339966;">-- row-data only , not LOB</span>

<span style="color: #0000ff;">GROUP BY</span> s.[Name], t.[name]
<span style="color: #0000ff;">ORDER BY</span> 1,2</pre>
<p>For a very swift explanation &#8211; <span style="color: #339966;">sys.schemas</span> and <span style="color: #339966;">sys.tables</span> list the schemas and tables in the database, so joining these together on <span style="color: #ff00ff;">schema_id</span> gives a list of all tables by schema in the database. Adding on <span style="color: #339966;">sys.partitions</span> then pulls in the partitions associated with each table, and finally <span style="color: #339966;">sys.allocation_units</span> pulls in the allocation units, which i&#8217;m not quite sure what they are &#8211; the guts of this query were pulled from another blog which I embarrasingly can&#8217;t trace back to now.</p>
<p>I&#8217;m no expert on DMV&#8217;s so if you have any views on the quality of this query &#8211; please leave a comment with your thoughts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bimonkey.com/2009/06/count-the-number-of-rows-in-every-table-in-a-database-in-no-time/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

