﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Pradyothana Shastry  / RowCount / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 22:52:59 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: RowCount</title><link>http://www.sqlservercentral.com/Forums/Topic1066126-2603-1.aspx</link><description>[code="sql"]DECLARE @tblROWCOUNT TABLE ("Db name" VARCHAR(1000),"Table Name" VARCHAR(400),"Row Count" BIGINT	)DECLARE @SQL NVARCHAR(MAX)SELECT @SQL = 'SELECT ''?'' ,o.name, i.rowcnt  FROM ?.sys.sysobjects o, ?.sys.sysindexes'			  +' i WHERE i.id = o.id AND indid IN(0,1) AND xtype = ''u'''			  +	'AND o.name &amp;lt;&amp;gt; ''sysdiagrams'' AND i.rowcnt &amp;gt; 0  ORDER BY i.rowcnt DESC'INSERT INTO @tblROWCOUNTEXEC Sp_msforeachdb   @SQLselect * from @tblROWCOUNT[/code]</description><pubDate>Wed, 27 Apr 2011 05:32:42 GMT</pubDate><dc:creator>Mitesh Oswal</dc:creator></item><item><title>RE: RowCount</title><link>http://www.sqlservercentral.com/Forums/Topic1066126-2603-1.aspx</link><description>[quote][b]seshasai.n (3/1/2011)[/b][hr]Hi,I dont think so, is it worked or not, better to use sp_spaceused system stored procedure in the cursor, or try to create a dynamic sql to find out row count as well as alternate methods.Regards,SeshaSai.[/quote]SeshaSai - sp_SpaceUsed works but its clunky, and thats being kind, to use as it requires a lot of hoop jumping to get the info on more then one object at a time.  I'm not saying the proposoed solution here is best nor worst, only that I wouldn't put sp_SpaceUsed as the better choice.If your using sp_SpaceUsed you should check out some of the other script samples on the site and see how you can get this info in a much more user friendly manner.</description><pubDate>Tue, 15 Mar 2011 14:03:56 GMT</pubDate><dc:creator>YSLGuru</dc:creator></item><item><title>RE: RowCount</title><link>http://www.sqlservercentral.com/Forums/Topic1066126-2603-1.aspx</link><description>Hi,I dont think so, is it worked or not, better to use sp_spaceused system stored procedure in the cursor, or try to create a dynamic sql to find out row count as well as alternate methods.Regards,SeshaSai.</description><pubDate>Tue, 01 Mar 2011 03:04:40 GMT</pubDate><dc:creator>seshasai.n</dc:creator></item><item><title>RE: RowCount</title><link>http://www.sqlservercentral.com/Forums/Topic1066126-2603-1.aspx</link><description>[quote][b]YSLGuru (2/25/2011)[/b][hr]Just curious but why is it that you guys who like to put everything on a new line do this for the SELECT, WHERE, GROUP BY and ORDER BY clauses but not for your FROM clause?  I'm not saying that this style is right or wrong I'm just curious why you aren't consistent by placing FROM on a line by itself too?[/quote]No particular reason other than that is the way I like it.</description><pubDate>Fri, 25 Feb 2011 11:52:52 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: RowCount</title><link>http://www.sqlservercentral.com/Forums/Topic1066126-2603-1.aspx</link><description>[quote][b]UMG Developer (2/18/2011)[/b][hr]Nice little script, but it will return multiple rows for partitioned tables. Here is an updated version that takes care of that:[code="sql"]SELECT  o.name AS "Table Name",  SUM(i.rowcnt) AS "Row Count"FROM sysobjects o  INNER JOIN sysindexes i    ON o.id = i.idWHERE  i.indid IN (0, 1)  AND o.xtype = 'u'  AND o.name &amp;lt;&amp;gt; 'sysdiagrams'GROUP BY  o.nameORDER BY  "Row Count" DESC;[/code]I, also, converted it to use an INNER JOIN instead of doing the join in the WHERE, as I think it makes the codes more readable.Of course I think that in 2005/2008/2008R2 the preferred method is to use sys.dm_db_partition_stats:[code="sql"]SELECT   OBJECT_NAME(object_id) AS "Table Name",   SUM(row_count) AS "Row Count"FROM sys.dm_db_partition_stats WHERE   index_id &amp;lt; 2   AND OBJECTPROPERTY(object_id, 'IsMSShipped') = 0 GROUP BY   object_idORDER BY   "Row Count" DESC;[/code][/quote]Just curious but why is it that you guys who like to put everything on a new line do this for the SELECT, WHERE, GROUP BY and ORDER BY clauses but not for your FROM clause?  I'm not saying that this style is right or wrong I'm just curious why you aren't consistent by placing FROM on a line by itself too?</description><pubDate>Fri, 25 Feb 2011 11:31:38 GMT</pubDate><dc:creator>YSLGuru</dc:creator></item><item><title>RE: RowCount</title><link>http://www.sqlservercentral.com/Forums/Topic1066126-2603-1.aspx</link><description>Nice little script, but it will return multiple rows for partitioned tables. Here is an updated version that takes care of that:[code="sql"]SELECT  o.name AS "Table Name",  SUM(i.rowcnt) AS "Row Count"FROM sysobjects o  INNER JOIN sysindexes i    ON o.id = i.idWHERE  i.indid IN (0, 1)  AND o.xtype = 'u'  AND o.name &amp;lt;&amp;gt; 'sysdiagrams'GROUP BY  o.nameORDER BY  "Row Count" DESC;[/code]I, also, converted it to use an INNER JOIN instead of doing the join in the WHERE, as I think it makes the codes more readable.Of course I think that in 2005/2008/2008R2 the preferred method is to use sys.dm_db_partition_stats:[code="sql"]SELECT   OBJECT_NAME(object_id) AS "Table Name",   SUM(row_count) AS "Row Count"FROM sys.dm_db_partition_stats WHERE   index_id &amp;lt; 2   AND OBJECTPROPERTY(object_id, 'IsMSShipped') = 0 GROUP BY   object_idORDER BY   "Row Count" DESC;[/code]</description><pubDate>Fri, 18 Feb 2011 11:00:34 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RowCount</title><link>http://www.sqlservercentral.com/Forums/Topic1066126-2603-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/T-SQL/72272/"&gt;RowCount&lt;/A&gt;[/B]</description><pubDate>Thu, 17 Feb 2011 20:39:39 GMT</pubDate><dc:creator>Pradyothana Shastry</dc:creator></item></channel></rss>