Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

RowCount Expand / Collapse
Author
Message
Posted Thursday, February 17, 2011 8:39 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, September 22, 2014 2:34 PM
Points: 1,687, Visits: 453
Comments posted to this topic are about the item RowCount


- Pradyothana


http://www.msqlserver.com
Post #1066126
Posted Friday, February 18, 2011 11:00 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 5, 2014 2:00 PM
Points: 2,160, Visits: 2,191
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;

Post #1066523
Posted Friday, February 25, 2011 11:31 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 12:05 PM
Points: 892, Visits: 1,559
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!
Post #1069775
Posted Friday, February 25, 2011 11:52 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 5, 2014 2:00 PM
Points: 2,160, Visits: 2,191
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.
Post #1069793
Posted Tuesday, March 1, 2011 3:04 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 3, 2014 3:58 AM
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.
Post #1071064
Posted Tuesday, March 15, 2011 2:03 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 12:05 PM
Points: 892, Visits: 1,559
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!
Post #1078636
Posted Wednesday, April 27, 2011 5:32 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Friday, August 29, 2014 11:34 PM
Points: 790, Visits: 646

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
Post #1099334
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse