|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 12:41 AM
Points: 711,
Visits: 209
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, September 06, 2010 1:23 AM
Points: 30,
Visits: 163
|
|
Very powerful script. Do you have the SQL Server 2000 version of this script?
Thank you, GT
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 12:41 AM
Points: 711,
Visits: 209
|
|
There has been added a version of this procedure for SQL Server 2000. It is waiting for approval now.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 2:04 PM
Points: 116,
Visits: 326
|
|
Maybe add
order by cat_name,sch_name,tab_name for the select statement from the temp table.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, March 05, 2010 5:05 AM
Points: 25,
Visits: 32
|
|
Hi Rafal, How about this code??
use [YourDatabase]; select a1.object_id , a2.name , a1.used_page_count * 8 as total_used_pages , cast(a1.used_page_count * 8 /1000 as varchar(10)) + 'MB' as SIZE_total_used_pages , a1.reserved_page_count * 8 as total_reserved_pages , a1.row_count from sys.dm_db_partition_stats a1 inner join sys.all_objects a2 on ( a1.object_id = a2.object_id ) left outer join sys.indexes a3 on ( (a1.object_id = a3.object_id) and (a1.index_id = a3.index_id) ) where (select count(distinct partition_number) from sys.dm_db_partition_stats a4 where (a4.object_id = a1.object_id)) >= 1 and a2.type <>'S' --and (a1.used_page_count * 8 /1000) > 1 --Uncomment this line to list tables that occupy >1MB space order by a1.used_page_count desc, a2.name asc, a1.index_id, a1.partition_number
I have not compared my code as against yours.. just thought of putting it up here.. so did I. :D
Will be glad if you replied on its worth!!! :) Thanks, Khilan
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Today @ 2:35 AM
Points: 276,
Visits: 328
|
|
Hi there,
Thanks for this script...I was looking for a script like this. I tried both the SQL2005 and the SQL2000 script. No problem with the first script but the second wouldn't run.
Msg 170, Level 15, State 1, Procedure proc_records_per_database, Line 43 Line 43: Incorrect syntax near ' '. I found a little typo in the script when creating the temp table:
create table #temp_table_list ( rec_id int identity(1, 1) not null, cat_name sysname not null, sch_name sysname not null, tab_name sysname not null, row_count bigint not null default 0, reserved_pages bigint not null default 0, reserved bigint not null default 0, pages bigint not null default 0, data bigint not null default 0, used_pages bigint not null default 0, used bigint not null default 0, index_size bigint not null default 0, not_used bigint not null default 0, primary key(rec_id) ) There are some unrecognized spaces (perhaps a tab) after "used_pages bigint not null default 0,". When you remove those the script works just fine :)
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:47 PM
Points: 360,
Visits: 1,072
|
|
Was the one for sql server 2000 approved? I cannot find it.
¤ §unshine ¤
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, October 15, 2010 8:23 AM
Points: 371,
Visits: 437
|
|
both scripts (2000 & 2005) run perfectly. This is a GOOD ONE. Thanks!!
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, August 26, 2011 2:10 PM
Points: 3,
Visits: 64
|
|
I have backed into a DBA role from a development background an I wonder why there isn't more discussion of [ Microsoft specific I think] SMO object model that affords you the ability to get row count and size of table plus more C# version of this.
Down side of this is it is outside the database [Using a database API though] and there is extremely little documentation more hacking around with it to find what is required unless someone knows of a good source[ The most that I have found is a book with three chapters on it that I have on order]
Certainly having a TSQL script to pull up in a database is probably the norm for DBA's but there could be occasion to write an application or service that may do this on demand or check against a predefined thresh hold and report to you when records exceed a certain predefined number though once again this could be done with a DTS package too
using System.Data.SqlClient; using Microsoft.SqlServer.Management; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Server; using Microsoft.SqlServer.Management.Smo;
con.ConnectionString = @ConnectStringSA; con.Open(); ServerConnection conn = new ServerConnection(con); Server svr = new Server(conn);
foreach (Table oTable in svr.Databases[@DBName].Tables) {
string sRowCount = oTable.RowCount.ToString(); string sDataSpace = oTable.DataSpaceUsed.ToString(); \\Yada Yada ya }
Has anyone else used SMO extensively?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Sunday, April 15, 2012 7:06 AM
Points: 122,
Visits: 205
|
|
I have written a short article regarding this.
Please check my blog and provide me your valuable feedback.
http://venkattechnicalblog.blogspot.com/2008/09/list-out-all-tables-and-row-count-in.html
Thanks and Regards, Venkatesan Prabu, :P My Blog:
http://venkattechnicalblog.blogspot.com/
|
|
|
|