February 17, 2011 at 8:39 pm
Comments posted to this topic are about the item RowCount
February 18, 2011 at 11:00 am
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;
February 25, 2011 at 11:31 am
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!February 25, 2011 at 11:52 am
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.
March 1, 2011 at 3:04 am
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.
March 15, 2011 at 2:03 pm
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!April 27, 2011 at 5:32 am
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
May 17, 2016 at 6:53 am
Thanks for the script.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply