|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, January 31, 2013 1:35 AM
Points: 19,
Visits: 60
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, April 23, 2013 6:51 AM
Points: 22,
Visits: 144
|
|
| Hi, but are the results correct or approximate?
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, December 07, 2010 2:34 AM
Points: 13,
Visits: 31
|
|
This is an interesting (and much quicker) method but I found the figures returned don't correlate exactly with results from 'select count(*) from <table name>' e.g. Select count = 14459745; SP_ROWCOUNT = 14459739 Select count = 1907910; SP_ROWCOUNT = 1907541
This may not be too important in whole table rowcounts, but do you know why this is?
Cheers
John
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 12:27 AM
Points: 483,
Visits: 1,191
|
|
Thats because statistics for the table is not updated Fire 'update statistics tablename' and check the results again.
Regards, Raj
Strictlysql.blogspot.com
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, December 07, 2010 2:34 AM
Points: 13,
Visits: 31
|
|
OK thanks. Of course that makes it a little less quick if you have to do an update statistics on the table before you can query it
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, December 07, 2010 2:34 AM
Points: 13,
Visits: 31
|
|
Well I just ran update statistics and re-ran SP_ROWCOUNT. I still got the same figures, so not only does update stats take longer than select count... it doesn't update the rowcount stats either 
Maybe I'll stick with select count...
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Yesterday @ 9:48 AM
Points: 713,
Visits: 2,842
|
|
Hello,
The script is fine but using MS_foreach is undocumented !  I prefer to use:
SELECT table_name,table_rows FROM ( select so.name as table_name, si.rowcnt as table_rows,ROW_NUMBER() OVER (PARTITION BY SO.NAME ORDER BY si.rowcnt DESC) AS RC from sysobjects so join sysindexes si on so.id = si.id and so.type = 'U' )F WHERE RC = 1 ORDER BY table_name
HTH, \\K
HTH, Cheers !
"Never take life too seriously, nobody gets out of it anyways ! When your love and skills unite, expect a masterpiece !"
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Yesterday @ 9:48 AM
Points: 713,
Visits: 2,842
|
|
Hello,
The script is fine but using MS_foreach is undocumented !  I prefer to use:
SELECT table_name,table_rows FROM ( select so.name as table_name, si.rowcnt as table_rows,ROW_NUMBER() OVER (PARTITION BY SO.NAME ORDER BY si.rowcnt DESC) AS RC from sysobjects so join sysindexes si on so.id = si.id and so.type = 'U' )F WHERE RC = 1 ORDER BY table_name
HTH, \\K
HTH, Cheers !
"Never take life too seriously, nobody gets out of it anyways ! When your love and skills unite, expect a masterpiece !"
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 12:27 AM
Points: 483,
Visits: 1,191
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 3:01 AM
Points: 266,
Visits: 1,023
|
|
I prefer to use system objects that aren't marked for removal from a future release of SQL Server, I prefer not to use undocumented stored procs, and I prefer accuracy in my results:
SELECT QUOTENAME(OBJECT_SCHEMA_NAME(ps.object_id)) + '.' + QUOTENAME(OBJECT_NAME(ps.object_id)) AS TableName, SUM(ps.row_count) AS row_count FROM sys.dm_db_partition_stats ps WHERE ps.index_id <= 1 AND OBJECTPROPERTY(ps.object_id, 'IsMSShipped') = 0 GROUP BY ps.object_id ORDER BY TableName Chris
|
|
|
|