Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


RowCount


RowCount

Author
Message
Pradyothana Shastry
Pradyothana Shastry
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1702 Visits: 481
Comments posted to this topic are about the item RowCount


- Pradyothana


http://www.msqlserver.com
UMG Developer
UMG Developer
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2280 Visits: 2204
Nice little script, but it will return multiple rows for partitioned tables. Here is an updated version that takes care of that:


SELECT
o.name AS "Table Name",
SUM(i.rowcnt) AS "Row Count"
FROM sysobjects o
INNER JOIN sysindexes i
ON o.id = i.id
WHERE
i.indid IN (0, 1)
AND o.xtype = 'u'
AND o.name <> 'sysdiagrams'
GROUP BY
o.name
ORDER BY
"Row Count" DESC;



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:


SELECT
OBJECT_NAME(object_id) AS "Table Name",
SUM(row_count) AS "Row Count"
FROM sys.dm_db_partition_stats
WHERE
index_id < 2
AND OBJECTPROPERTY(object_id, 'IsMSShipped') = 0
GROUP BY
object_id
ORDER BY
"Row Count" DESC;


YSLGuru
YSLGuru
SSC Eights!
SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)

Group: General Forum Members
Points: 959 Visits: 1659
UMG Developer (2/18/2011)
Nice little script, but it will return multiple rows for partitioned tables. Here is an updated version that takes care of that:


SELECT
o.name AS "Table Name",
SUM(i.rowcnt) AS "Row Count"
FROM sysobjects o
INNER JOIN sysindexes i
ON o.id = i.id
WHERE
i.indid IN (0, 1)
AND o.xtype = 'u'
AND o.name <> 'sysdiagrams'
GROUP BY
o.name
ORDER BY
"Row Count" DESC;



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:


SELECT
OBJECT_NAME(object_id) AS "Table Name",
SUM(row_count) AS "Row Count"
FROM sys.dm_db_partition_stats
WHERE
index_id < 2
AND OBJECTPROPERTY(object_id, 'IsMSShipped') = 0
GROUP BY
object_id
ORDER BY
"Row Count" DESC;



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?

Kindest Regards,

Just say No to Facebook!
UMG Developer
UMG Developer
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2280 Visits: 2204
YSLGuru (2/25/2011)
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?


No particular reason other than that is the way I like it.
seshasai.n
seshasai.n
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 93
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.
YSLGuru
YSLGuru
SSC Eights!
SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)

Group: General Forum Members
Points: 959 Visits: 1659
seshasai.n (3/1/2011)
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.



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.

Kindest Regards,

Just say No to Facebook!
Mitesh Oswal
Mitesh Oswal
Right there with Babe
Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)

Group: General Forum Members
Points: 798 Visits: 653


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 <> ''sysdiagrams'' AND i.rowcnt > 0 ORDER BY i.rowcnt DESC'

INSERT INTO @tblROWCOUNT

EXEC Sp_msforeachdb @SQL

select * from @tblROWCOUNT




Regards,
Mitesh OSwal
+918698619998
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8660 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search