|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Monday, March 25, 2013 5:30 AM
Points: 1,640,
Visits: 423
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
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;
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:38 PM
Points: 846,
Visits: 1,451
|
|
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,
A Democracy works great until the day you find yourself on the sheep side of a vote between 5 wolves and 4 sheep on what’s for dinner when neither have eaten in many days. A free Republic where the rights of the few and the individual are protected is the only one in which Freedom and Prosperity for all have a chance to blossom.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
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.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 9:52 AM
Points: 2,
Visits: 82
|
|
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.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:38 PM
Points: 846,
Visits: 1,451
|
|
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,
A Democracy works great until the day you find yourself on the sheep side of a vote between 5 wolves and 4 sheep on what’s for dinner when neither have eaten in many days. A free Republic where the rights of the few and the individual are protected is the only one in which Freedom and Prosperity for all have a chance to blossom.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, February 15, 2013 1:56 AM
Points: 593,
Visits: 371
|
|
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
|
|
|
|