SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


RowCount


RowCount

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

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


- Pradyothana


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

Group: General Forum Members
Points: 2708 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
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1834 Visits: 1665
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.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2708 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 (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 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
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1834 Visits: 1665
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
SSC Eights!
SSC Eights! (916 reputation)SSC Eights! (916 reputation)SSC Eights! (916 reputation)SSC Eights! (916 reputation)SSC Eights! (916 reputation)SSC Eights! (916 reputation)SSC Eights! (916 reputation)SSC Eights! (916 reputation)

Group: General Forum Members
Points: 916 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
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13954 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