Table Size from SQL
-
Saturday, April 28, 2012 8:54 AM
Hi team ,
How to identify the table size from Database for past 10 days. i.e Table name <ABCD> , i need to know the size of the table for past 10 days.How much size has been grown day wise ? like this information.
please share me if any query is there to obtain the same through query analyzer
- Moved by Janet YeildingMicrosoft Employee Monday, April 30, 2012 6:08 PM (From:SQL Server Data Tools)
All Replies
-
Monday, April 30, 2012 10:24 PM
One way to get the table size in MB is
SELECT convert(bigint, reserved) * 8192 / 1000000
FROM sysindexes
WHERE id = object_id('tablename')
AND indid IN (0, 1)You need to run this every day (or every tenth day) to be able to make any calculations; SQL Server does not save any historic data for you.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se- Marked As Answer by Stephanie LvModerator Thursday, May 10, 2012 5:01 AM
-
Monday, April 30, 2012 11:10 PM
Check this post it may be useful
http://alihamdar.com/2012/04/27/how-to-find-big-tables-in-your-database/
Ali Hamdar (alihamdar.com - www.ids.com.lb)
-
Tuesday, May 01, 2012 1:26 AMYou can use sp_spaceused to get current size of the table, but need to run everyday to get growth info.
-
Tuesday, May 08, 2012 12:23 AMModerator
You have to setup a size logging table, write a stored procedure to record the size and schedule the sp as a job for periodic execution. Table size blog post:
http://www.sqlusa.com/bestpractices2008/table-sizes/
Kalman Toth SQL SERVER 2012 & BI TRAINING
New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012- Marked As Answer by Stephanie LvModerator Thursday, May 10, 2012 5:01 AM
- Edited by Kalman TothMicrosoft Community Contributor, Moderator Monday, October 08, 2012 12:31 AM
-
Tuesday, May 08, 2012 12:49 AM
Please see the below link
ESHANI. Please click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you
-
Tuesday, May 08, 2012 2:56 AM
SQL Server does not keep a history of the table sizes over time automatically.
SP_SPACEUSED 'tablename' command can be used to find the size of the table at that specific time.
As mentioned by others too in this thread, if you want to see size change over time then you'll have to create a job/process that captures the output of SP_SPACEUSED (or other script are possible too) at a defined interval i.e. daily, weekly fortnightly etc. As this process builds the size history, you can create reports based on that data.
One of the methods to implement such a process is at the below URLs. They are quick reads so I'd suggest that you read both of them.
http://www.techrepublic.com/blog/datacenter/capturing-sql-server-2005-database-file-size-information/292?tag=rbxccnbtr1
http://www.techrepublic.com/blog/datacenter/monitor-database-file-sizes-with-sql-server-jobs/296?tag=rbxccnbtr1
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers.
Thanks!
Aalam | Blog (http://aalamrangi.wordpress.com)- Edited by Aalam Rangi Tuesday, May 08, 2012 3:11 AM fixed typo
- Proposed As Answer by Naomi NMicrosoft Community Contributor, Moderator Tuesday, May 08, 2012 3:54 PM
- Marked As Answer by Stephanie LvModerator Thursday, May 10, 2012 5:01 AM
-
Tuesday, May 08, 2012 5:08 AM
Hi
Every x amount of days check using sql table size and insert into a table (snapshot it) and then compare.
Hope that helps
Emil
Katie & Emil Microsoft SQL BI related blog & tutorials SQL Tutorial | SSRS Tutorial | SSIS Tutorial
-
Tuesday, May 08, 2012 7:31 AM
IF object_id('tempdb..#TableSize') IS NOT NULLBEGIN
DROP TABLE #TableSize
END
create table #TableSize (name varchar(150), rows int, reserved varchar(150)
,data varchar(150), index_size varchar(150), unused varchar(150))
insert into #TableSize
EXEC sp_MSforeachtable @command1='EXEC sp_spaceused ''?'''
select name, cast(replace(data, ' KB','') as int)/1024 as TableDataSizeMB
from #TableSize
order by cast(replace(data, ' KB','') as int) desc
drop table #TableSize
Shamas Saeed (if Post helpful please mark as Answer) http://shamas-saeed.blogspot.com

